New variables in a loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone! I'm facing some issues while trying to create new variables inside a for loop. Here is the first part of my code. My question is wheter i can load my data using a for loop while keeping first character (m) and changing 15,20,25,30 and A,B,C....J.
load m15A
load m15B
load m15C
load m15D
load m15E
load m15F
load m15G
load m15H
load m15I
load m15J
load m20A
load m20B
load m20C
load m20D
load m20E
load m20F
load m20G
load m20H
load m20I
load m20J
load m25A
load m25B
load m25C
load m25D
load m25E
load m25F
load m25G
load m30A
load m30B
load m30C
load m30D
load m30E
load m30F
load m30G
load m30H
My second question is how can i assign new variables winside a for loop. I tried something like this but did not worked:
for i=1:35
Fs_{i}=(L(i)/tmax(i));
end
for j=1:35
for k=15:5:35
t{j}=m(k)A(:,1);
acc{j}=m(k)A(:,2);
end
end
Thanks in advance!
L1=length(m15A);
t_max1=max(m15A(:,1));
L2=length(m15B);
t_max2=max(m15B(:,1));
L3=length(m15C);
t_max3=max(m15C(:,1));
.....
.....
.....
L34=length(m30G);
t_max34=max(m30G(:,1));
L35=length(m30H);
t_max35=max(m30H(:,1));
%% Calc sampling frequency
Fs_1=L1/t_max1;
Fs_2=L2/t_max2;
Fs_3=L3/t_max3;
........
........
........
Fs_34=L34/t_max34;
Fs_35=L35/t_max35;
%% Assign Collumns
t1=m15A(:,1);
acc1=m15A(:,2);
t2=m15B(:,1);
acc2=m15B(:,2);
......
......
......
t35=m30H(:,1);
acc35=m30H(:,2);
0 commentaires
Réponses (1)
KALYAN ACHARJYA
le 25 Déc 2019
Modifié(e) : KALYAN ACHARJYA
le 25 Déc 2019
Considering the array or cell array is best way rather than assigning new variable in each iteration.
Fs=zeros(1,35);
for i=1:35
Fs(i)=L(i)/tmax(i); % assuming L and tmax both are scalars
end
% Assuming L and tmax both are scalars, if not then
Fs=cell(1,35);
for i=1:35
Fs{i}=L(i)/tmax(i);
end
2 commentaires
Voir également
Catégories
En savoir plus sur Animation 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!