loops and xlsread.

7 views (last 30 days)
franco otaola
franco otaola on 5 Oct 2016
Commented: dpb on 7 Oct 2016
hello everybody,
I am new at using the program, i worked with maple before and i reason with its logic i am using the matlab to reduce some noise of some measures and every xls i export has the name 1.xls, 2.xls, 3.xls...like that until 75.xls and each one has a measure i made. After smoothing each measure, I need to calculate the surface and graph it with the A matrix. so I though of doing something like the code below.
for i=1:75 %all the excels i have
Graph=[A(i) surf(i)]
I know that the program is going to search for the i.xls file and not for 1.xls, 2.xls, 3.xls...etc. I made it so everybody could understand better the logic i took. anyone knows a way to doing it? thanks

Accepted Answer

dpb on 5 Oct 2016
A=[[0.5:0.5:21[ 22:35]; % use colon; recommend using the "Getting Started" tutorials
See the FAQ <process a sequence of files>. I'm particularly fond of the dir solution w/ wildcard for cases such as you show.
d=dir('*.xls'); % get the list of files...
for i=1:length(d) % and iterate over it...
values=xlsread(d(i).name,'B10:B5010'); % read the spreadsheet...
At this point, do the operations on the specific dataset and move on to the next. Doesn't look like you need to hold all in memory at once.
dpb on 7 Oct 2016
Have you used the text-based help command from the command line or just the documentation for individual functions or the general documentation. While not pretty, what it does is let you "drill down" from the various subdirectories by which Matlab organizes functions, giving you the list of what those are and then if there's a category of interest, using that category/directory as the argument gives an overview list of all functions and the one-line help. That can be invaluable aid in finding the function(s) related to what it is you're looking for at the time in a quicker way than the other documentation. You then use that doc to find out the details.
That's a "brute force" technique but is well worth doing a few times just to gain some familiarity with the contents...recollecting you've seen something like that in the past is helpful even if can't remember a tenth of it specifically, the generalities are beneficial.
OTOH, lookfor is a search tool for a keyword that you think could be related to the topic you're searching for the tools available for...
>> help lookfor
lookfor Search all M-files for keyword.
lookfor XYZ looks for the string XYZ in the first comment line
(the H1 line) of the HELP text in all M-files found on MATLABPATH
(including private directories). For all files in which a
match occurs, lookfor displays the H1 line.
In summary, WHAT lists the functions in a given directory,
WHICH finds the directory containing a given function or file, and
lookfor finds all functions in all directories that might have
something to do with a given key word.

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 5 Oct 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by