How to save different files in for loop

4 vues (au cours des 30 derniers jours)
Jiwoo Seo
Jiwoo Seo le 27 Sep 2020
Commenté : Jiwoo Seo le 27 Sep 2020
Hi,
I'm trying to create separate folders each with a .mat file with temperature data in them (from Feb01 to Apr30). The folders should be like so:
ex) Feb01 folder > Feb01.mat (this .mat file should have 24 temperature data values in them)
But when I run my code I get an error message that says:
Error using save
Must be a text scalar.
Error in Copy_of_testingdates (line 46)
save(FileName,'DataAdj')
Here is my code:
%calibration data
run('HoboConstants.m')
%read data from Feb01 to Apr30
HoboData_C=readmatrix('AB1_Jan22_to_May3.csv','Range','B234:C2393');
HoboData=HoboData_C(:,2)+273.15;
%set month and date vectors
month={'Feb','Mar','Apr'}; %had to attach them bc k reads one alphabet as one column
max_date=[28 31 30];
FileName1={};
DataAdj=[];
FullHoboAdj=[];
%set constants
k=1;
q=1;
m=1;
%saving separate files as ex)"Feb22"
for i=1:24:2136 %decreased 2160 by 24 so that loop runs 89 times
%calibrate data
DataAdj=HoboData(i:(i+23),1)-hoboAB1;
%gives the full calibrated data from Feb01 to Apr30
FullHoboAdj=[FullHoboAdj;DataAdj];
if q>max_date(m)
q=1;
if m<=length(max_date)
m=m+1;
end
if k<=length(month)
k=k+1;
end
end
%creating FileName
z=length(FileName1);
%this will name FileName1 as 'Jan01' up to 'Apr29'
FileName1{z+1}=sprintf('%s%02d',month{k},q);
%flipping the horizontal FileName1 to be vertical
FileName=reshape(FileName1',{},1);
q=q+1;
save(FileName,'DataAdj') %#####This is where the error is#####
end
Thank you!

Réponse acceptée

Walter Roberson
Walter Roberson le 27 Sep 2020
FileName = FileName1{z+1};
  1 commentaire
Jiwoo Seo
Jiwoo Seo le 27 Sep 2020
Thank you SO MUCH!! I can't believe this simple code solved everything!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by