matlab

matlab quickie: test if text file is empty

Simple question: I am opening a file in matlab 7.x, and I want to test if it is empty before reading it. What's the best way to do this? ...

MATLAB runs out of memory during program execution

I have been happily using MATLAB to solve some project Euler problems. Yesterday, I wrote some code to solve one of these problems (14). When I write code containing long loops I always test the code by running it with short loops. If it runs fine and it does what it's supposed to do I assume this will also be the case when the length of...

Using find function on columns and rows in matlab

Hi, I am having some problems with the find function in MATLAB. I have a matrix consisting of zeros and ones (representing the geometry of a structural element), where material is present when the matrix element = 1, and where no material is present when the matrix element = 0. The matrix may have the general form shown below (it will ...

Generating vectors in MATLAB

Hi. I am wondering whether there is an efficient way in MATLAB to generate all vectors of a fixed length with elements from a finite set. For instance, how can I build all vectors of length 5 with only 0 or 1 as elements? ...

MATLAB - matrix combinations

I am fairly new to MATLAB and I am having trouble figuring out an efficient solution for a problem. Any help would be greatly appreciated!! I have a 2D matrix containing various angles between lines that looks like L1 L2 L3 L4 L5 L6 L1 0 40 90 0 10 0 L2 40 0 0 5 40 20 L3 90 0 0 45 0 ...

Converting rgb images to grayscale and renaming them using matlab

Hello, I have 500 images named Image1.tif all the way to Image500.tif and I need to convert all of them to grayscale and save them as Image1A.tif to Image500A.tif. Is there a quick way to do this? Thank you. ...

MATLAB - Redefine YTickLabel

I have a problem with editing the colorbar in MATLAB. The colorbar is drawn and I want to add the unit (dB) for the specific measurement on YTickLabels. This is done by following commands: cy = get(ch,'YTickLabel'); set(ch,'YTickLabel',[]); set(ch,'YTickLabel',strcat(cy,{' dB'})); But when I resize the figure, MATLAB redefines th...

Is there a way how to run MATLAB script from specific line without GUI?

Is there a way how to run MATLAB script from specific line without using GUI. In GUI I use %%. Thanks ...

What do I have to add at the beginning of this loop ??

how I can read the following files using the for loop: (can the loop ignore the characters in filenames?) abc-1.TXT cde-2.TXT ser-3.TXT wsz-4.TXT aqz-5.TXT iop-6.TXT What do I have to add at the beginning of this loop ?? for i = 1:1:6 nom_fichier = strcat(['MyFile\.......' num2str(i) '.TXT']); ...

Reducing Mean Square Error

The topic of mine is face recognition using artificial neural networks using MATLAB code. I tried my work by taking the images from web and started implementing the program by using neural networks. By typing nprtool command in MATLAB ,i started training, testing and validating the images from database. When i started to calculate the...

Matlab Error: ??? Cell contents reference from a non-cell array object.

After asking this question: how I can read the following files using the for loop: (can the loop ignore the characters in filenames?) abc-1.TXT cde-2.TXT ser-3.TXT wsz-4.TXT aqz-5.TXT iop-6.TXT ... (In fact, I have 500 files) What do I have to add at the beginning of this loop ?? for i = 1:1:50...

Matlab: How can I change the following program

I have 500 files .TXT, for example: abc-1.TXT adfer-2.txt affd-3.TXT asxdcccc-4.TXT ... How can I change the following program to achieve results in order of numbers in the filenames: Names = dir('MyFile\*.TXT'); for i = 1:500 fn = strcat(['MyFile\' Names(i).name]); ... is there a way to make the loop on th...

Plotting a series of 2D black and white plots in MATLAB

Hi, I am trying to plot a series of 2D matrices containing ones and zeros (effectively black and white images) in matlab, which are ordered in 3D. The code I have so far is: function PlotthreeD() numrows = 100; numcols = 100; Plot1 = zeros(numcols); Plot1(20:50,20:50) = 1; Plot2 = zeros(numcols); Plot1(20:70,20:90) = 1; Plo...

How do i rewrite equations from matlab for use in c++

I have derived and simplified an equation in Matlab and want to use it in a c++ program. Matlab likes to use powers, the ^ sign but c++ doesn't like it one bit. How can i get Matlab to rewrite the equation so that it outputs a c++ friendly equation? ...

MATLAB combining edge region back into image

I don't know if this is possible, but here goes anyways. I would like to extract the edges from an image (I was thinking of using imfilter(i,fspecial('sobel')) for this, then once the edges have been extracted I would like to manipulate the image representing the edges and then once the manipulation has been performed recombine the modi...

How to interpolate the coordinates of a vector on an image using MATLAB?

For instance, if I have got a vector describing a rectangle xy=[165 88; 401 88; 401 278; 165 278]; on an image. How can I obtain the following vector [165 88; % increase X - hold y 166 88; 167 88; ... ; 399 88; 400 88; 401 88; % hold x - increase y 401 89; 401 90; 401 91; ... ; 4...

How to optimize MATLAB loops?

I have been working lately on a number of iterative algorithms in MATLAB, and been getting hit hard by MATLAB's performance (or lack thereof) when it comes to loops. I'm aware of the benefit of vectorizing code when possible, but are there any tools for optimization when you need the loop for your algorithm? I am aware of the MEX-file ...

Maximum expression string length in regexp (MATLAB)

I wonder how long expression string one can use in REGEXP function in MATLAB? For example to list many words to match, like 'abc|defg|hij|...'. Worked fine for me with about 500 words (~3K characters), but with very large list (>300K) MATLAB just crashed without any error log. Anybody have an idea on the limit? May it depend in expressi...

How to recognize overflow bugs in Matlab?

I spent part of yesterday and today tracking down a bug in some Matlab code. I had thought my problem was indexing (with many structures that I didn't define and am still getting used to), but it turned out to be an overflow bug. I missed this for a very specific reason: >> uint8(2) - uint8(1) ans = 1 >> uint8(2) - uint8(2) an...

How can I create a cell of strings out of a meshgrid in MATLAB?

I have a library function that takes parameters as a text string (it's a general C library with a MATLAB frontend). I want to call it with a set of parameters like this: '-a 0 -b 1' '-a 0 -b 2' '-a 0 -b 3' '-a 1 -b 1' '-a 1 -b 2' '-a 1 -b 3' etc... I'm creating the values of a and b with meshgrid: [a,b] = meshgrid(0:5, 1:3); whic...