0
votes

I need to load and do some maths with 32 files (extension .mat) at the same time. So, after running the code, I expect to have 32 results of the maths.

The problem is that all the codes I'm trying just load the first or the last file.

The name of my files are: 21 pcb 11_01.mat; 21 pcb 11_02 ....21 pcb 11_32. I've tried this:

    for i=1:32 
    filename=strcat("21 pcb 11_",sprintf("%02d",i),".mat") 
    load(filename) 
    endfor 

As a result, the code only shows the last file in the workspace. I expected the code to load the 32 files.

Can you help me?

1
Loading a file creates some variables in the workspace, namely the variables contained in the file, What do the files contain? If they have the same variable names, loading the last file will overwrite any previous variablesLuis Mendo
You can only load one file at a time, so the process is load the file, do the maths and move on to the next file. Alternatively, you can load all 32 files one after the other, and then do the maths, but as @LuisMendo mentions, if the variables in your *.mat files have the same name, they will get overwritten with each load operation. If that's the case, you want to store the data in a uniquely named variable at each iteration of load. Without more information on what's in the *.mat files, it's difficult to say anymore.am304
Thanks for the answers! It is a Picoscope file (a type of oscilloscope). Therefore, in each file, there is the same variable name (called A), but the values of this variable are different in each file.Priscilla Neves

1 Answers

1
votes

If your Picoscope files are all the same length, say Lpico, then this ought to work:

Pico=NaN*ones(32,Lpico);
for k=1:32
  filename=strcat("21 pcb 11_",sprintf("%02d",i),".mat") 
  load(filename)
  Lthisrun=length(A);
  Pico(k,1:Lthisrun)=A;
endfor 

If they have different length, then make Lpico as long as the longest A. Shorter scope ouputs will be padded with NaN's