loops and xlsread.

1 次查看(过去 30 天)
franco otaola
franco otaola 2016-10-5
评论: dpb 2016-10-7
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.
A=[0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]
for i=1:75 %all the excels i have
[values(i)]=xlsread('i.xls','B10:B5010');
smooth(i)=sgolayfilt(values(i),1,447);
surf(i)=trapz(0.04,smooth(i));
Graph=[A(i) surf(i)]
end
plot(Graph)
xlswrite('essai',Graph)
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

采纳的回答

dpb
dpb 2016-10-5
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.
  6 个评论
franco otaola
franco otaola 2016-10-7
thanks! yes i am using the help(and the question already asked from other people), now i am going to give a try to the look for! thanks. i found that function but sometimes i dont understand how to use them,for example for this function i didnt catch it yet.... i find a little difficult the logic sometimes in matlab (it is difficult to change between softwares ahahaha) but i begin understanding. i will keep working in it and reading the help :) thanks for taking the time!
dpb
dpb 2016-10-7
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.

请先登录,再进行评论。

更多回答(1 个)

Steven Lord
Steven Lord 2016-10-5

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by