Hello everyone,
I have been working on a script where I have to store multiple files (say 10 files) like TestingFile1, TestingFile2 and so on...
This code is working but it only stores the last value of T. The code is shown below
for one = 1:length(p)
for two= 1:length(o)
T = table(c{1,2}.time, oo{1,two}.signals.values, pp{1,one}.signals.values)
end
end
writetable(T,'TestingFile.xlsx'); %problem in this part
Any help would be highly appreciated.
PS: The length of one and two is equal.

 채택된 답변

Rik
Rik 2022년 1월 12일

0 개 추천

Use sprintf to create a filename based on your variables.
for one = 1:numel(p)
for two= 1:numel(o)
T = table(c{1,2}.time, oo{1,two}.signals.values, pp{1,one}.signals.values);
filename=sprintf('TestingFile_%d_%d.xlsx',one,two);
writetable(T,filename);
end
end

댓글 수: 3

Hi @Rik, Thank you for the response but I have to save file in a format "TestingFile1,TestingFile2 and so on..."
This has to be no link with the variables, one and two. Hope I conveyed my point!
Something like this maybe;
save = 1:3
for one = 1:numel(pp)
for two= 1:numel(oo)
T = table(c{1,2}.time, oo{1,two}.signals.values, pp{1,one}.signals.values);
filename=sprintf('TestingFile.xlsx',save);
writetable(T,filename);
end
end
Rik
Rik 2022년 1월 12일
Have you read the documentation for sprintf?
If you need a file counter, why don't you use and explicit one? You're close with the code you've written so far. Just set a counter before your loop and increment it inside your loop.
Sugar Mummy
Sugar Mummy 2022년 1월 12일
@Rik, It worked. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2022년 1월 12일

댓글:

2022년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by