I have done calculations on charging of an electric vehicle. For this I have created a charging profile for 1 car.
Now I want to make one for 429 cars.
So my question is, how do I save my charging profile in a for loop to multiple .mat files?
The output of the script is T which is a 13377x2 double for Car 1 and 15194x2 doublefor Car 2
I have tried for two cars
ID=[1 2]
for i=1:length(ID)
.
.THE SCRIPT
T
end
What I want is:
T1.mat and T2.mat

 Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 10 Mär. 2021

0 Stimmen

hello
why not simply store the T1 and T2 as cell arrays indexed with the loop index i ?
for i = 1:429
...code here ....
T1{i} = .... ;% 13377x2 double
T2{i} = .... ;% 15194x2 double
end
save T1.mat T1
save T2.mat T2

4 Kommentare

Joel Schelander
Joel Schelander am 10 Mär. 2021
Each vehicle will have a different matrix. The output from the loop will always be T
I want to save T on every iteration into files, above was just an example
Mathieu NOE
Mathieu NOE am 10 Mär. 2021
Ok
so there is only one T matrix to save
for i = 1:429
...code here ....
T{i} = .... ;
end
save T.mat T
Joel Schelander
Joel Schelander am 10 Mär. 2021
yes, I tried saving into cells like the code you posted, but it only stores the last matrix in the loop
Mathieu NOE
Mathieu NOE am 11 Mär. 2021
that's very strange
here a test on 4 iterations
for i = 1:4
...code here ....
T{i} = 10*i+rand(5,i) ;
end
save T.mat T
when I load again T after having cleared the workspace, I can get my four cells from T :
T = 1×4 cell array
{5×1 double} {5×2 double} {5×3 double} {5×4 double}

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by