Prev: Voronoi Polygon Areas
Next: image processing
From: hank scorpio on 8 Apr 2010 00:05 Hello, I have made a script that runs a loop iterating through up to and over a million+ times - I can see processing times will run in the days doing it the way have programmed it... For each iteration a file is read and a little data extracted from it which is written to an array for later use. I thought rather than read an external file in every loop iteration I might get somewhere faster by having the all the files data already in matlab at the outset so I'd just read the data from within matlab. Even though some of the files might not be called to be read, It's likely most will so I'm happy to import them all at the outset which would equate to ONE read per file rather than potentially hundreds+ (am I trading RAM for um, disk or processor speed here !?) Anyway, I thought I'd write the following to get the files into Matlab: for a = 1:totaltiffs tiffhandle = sprintf('//tiff/%s%d.tif',tiffname, a); INtiff = Tiff(tiffhandle, 'r'); sprintf('INtiffdata%d', a) = INtiff.read(); end which gives me "??? Subscripted assignment dimension mismatch." sprintf('INtiffdata%d', a) gives me: INtiffdata1 INtiffdata1 = INtiff.read(); gives me what I want (to test my speed theory) - i.e. INtiffdata is an array of tiff data but sprintf('INtiffdata%d', a) = INtiff.read(); doesn't work ... I can't yet figure out how "??? Subscripted assignment dimension mismatch." comes into it. What is going on ? hmmmmmm ooooor - is this just a waste of time and I need to think another way to get more speed out of the script ? total beginner here ;)
From: Walter Roberson on 8 Apr 2010 00:22 hank scorpio wrote: > sprintf('INtiffdata%d', a) = INtiff.read(); sprintf() is a function that returns a character string. You then try to assign the tiff data (which is not character) to the space occupied by the character string. The size of the character string is not the same as the size of the tiff data, so you get "Subscripted assignment dimension mismatch". Besides, you aren't allowed to assign a value to the result of an expression, just like you aren't allowed to say [1 2 3] = [4 5 6] since the [1 2 3] is only a temporary object. Please read the following FAQ answer: http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F Which-ever approach you take, remember to pre-allocate memory when possible, rather than relying on Matlab to grow the array (or cell array, or structure) at need. Pre-allocation can make an amazing performance difference.
From: hank scorpio on 8 Apr 2010 03:48 HA! thank you very much I just increased the speed of my script by a factor of 4000 yup, 4000 !
|
Pages: 1 Prev: Voronoi Polygon Areas Next: image processing |