|
From: | Rick T |
Subject: | Re: splitting arrays then exporting them to file |
Date: | Sun, 9 Oct 2011 04:04:36 -1000 |
From: address@hidden [mailto:address@hidden] On Behalf Of Rick T
Sent: Friday, October 07, 2011 10:53 AM
To: address@hidden
Subject: splitting arrays then exporting them to file
Greetings All
I'm trying to split arrays into 500 rows then export those 500 rows out as files
I was going to create an array that stored the index of 500 rows example (1,500,1000,1500) then call that array as the index but it seems the wrong way / convoluted way to do things any suggestions
clear all
t = rand(15679,1);
chunkidx=1;
for ii=1:500:length(t), %build array of desired ranges
chunkidx(end+1,:)=ii-1; %minus 1 to get correct array index in cell
end;
--
Thanks
Rick
Rick
Not sure why you want to chunk in sections of 500 but if you are already looping though the array just save in 500 element sections.
LEN = length(t)
for ii=1:500:LEN
if ( ii > (LEN-500) )
file_write( t(ii:(end)), sprintf( 'filename%d.extension', floor(ii/500)+1 ) )
else
file_write( t(ii:(ii+500)), sprintf( 'filename%d.extension', floor(ii/500)+1 ) )
end
end
Note: file_write is a placeholder because you were unclear if the file save was oct, mat, text, csv, or other. The sprintf is to autolabel the files saved to the local path. I don't think there is a looped file output but I could be wrong.
William Krekeler
[Prev in Thread] | Current Thread | [Next in Thread] |