How to work on "for loop" to save different column variable values to single vector?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
My question is=>
i have two variables, Ea and Ed, Ea contains single value and Ed contains 4 values like this,
Ea=10.5
Ed=51.6149 27.1981 13.2580 2.3396
These are wave energy values for 1 second of audio clip. But i have to calculate energy values for 60 seconds. So i have done storing each energy values in different variables like, Ed1, Ed2, Ed3...Ed60. These are Ed values for 60 seconds.
Now the problem i ve got is=>
i want to store all 1st column values of each variable(Ed1,Ed2,Ed3 till Ed60) in one vector(VEd1,VEd2,VEd3 and VEd4), so that i can draw or plot graph to analyze.
Here VEd1 should contain only 1st column values of all Ed values and also VEd2, VEd3 and VEd4.
I have tried "for" loop but could not get how to do tat... If i wont use any loops here, i wont b able to finish this before my dead line as i have to train the module for different audios.
Here is whatever i have tried... but i got errors...
for i=1:60,
VEa=Ea(i);
end
ERROR: Attempted to access Ea(2); index out of bounds because numel(Ea)=1.
then tried=>
for i=1:60,
VEa=Ea.i;
end
ERROR: Attempt to reference field of non-structure array.
Then i satisfied with this=>
for i=1,
VEd1=[Ed1(i) Ed2(i) Ed3(i) Ed4(i) Ed5(i) Ed6(i) Ed7(i) Ed8(i) Ed9(i) Ed10(i) Ed11(i) Ed12(i) Ed13(i) Ed14(i) Ed15(i) Ed16(i) Ed17(i) Ed18(i) Ed19(i) Ed20(i) Ed21(i) Ed22(i) Ed23(i) Ed24(i) Ed25(i) Ed26(i) Ed27(i) Ed28(i) Ed29(i) Ed30(i) Ed31(i) Ed32(i) Ed33(i) Ed34(i) Ed35(i) Ed36(i) Ed37(i) Ed38(i) Ed39(i) Ed40(i) Ed41(i) Ed42(i) Ed43(i) Ed44(i) Ed45(i) Ed46(i) Ed47(i) Ed48(i) Ed49(i) Ed50(i) Ed51(i) Ed52(i) Ed53(i) Ed54(i) Ed55(i) Ed56(i) Ed57(i) Ed58(i) Ed59(i) Ed60(i)];
end
for i=2,
VEd2=[Ed1(i) Ed2(i) Ed3(i) Ed4(i) Ed5(i) Ed6(i) Ed7(i) Ed8(i) Ed9(i) Ed10(i) Ed11(i) Ed12(i) Ed13(i) Ed14(i) Ed15(i) Ed16(i) Ed17(i) Ed18(i) Ed19(i) Ed20(i) Ed21(i) Ed22(i) Ed23(i) Ed24(i) Ed25(i) Ed26(i) Ed27(i) Ed28(i) Ed29(i) Ed30(i) Ed31(i) Ed32(i) Ed33(i) Ed34(i) Ed35(i) Ed36(i) Ed37(i) Ed38(i) Ed39(i) Ed40(i) Ed41(i) Ed42(i) Ed43(i) Ed44(i) Ed45(i) Ed46(i) Ed47(i) Ed48(i) Ed49(i) Ed50(i) Ed51(i) Ed52(i) Ed53(i) Ed54(i) Ed55(i) Ed56(i) Ed57(i) Ed58(i) Ed59(i) Ed60(i)];
end
for i=3,
VEd3=[Ed1(i) Ed2(i) Ed3(i) Ed4(i) Ed5(i) Ed6(i) Ed7(i) Ed8(i) Ed9(i) Ed10(i) Ed11(i) Ed12(i) Ed13(i) Ed14(i) Ed15(i) Ed16(i) Ed17(i) Ed18(i) Ed19(i) Ed20(i) Ed21(i) Ed22(i) Ed23(i) Ed24(i) Ed25(i) Ed26(i) Ed27(i) Ed28(i) Ed29(i) Ed30(i) Ed31(i) Ed32(i) Ed33(i) Ed34(i) Ed35(i) Ed36(i) Ed37(i) Ed38(i) Ed39(i) Ed40(i) Ed41(i) Ed42(i) Ed43(i) Ed44(i) Ed45(i) Ed46(i) Ed47(i) Ed48(i) Ed49(i) Ed50(i) Ed51(i) Ed52(i) Ed53(i) Ed54(i) Ed55(i) Ed56(i) Ed57(i) Ed58(i) Ed59(i) Ed60(i)];
end
for i=4,
VEd4=[Ed1(i) Ed2(i) Ed3(i) Ed4(i) Ed5(i) Ed6(i) Ed7(i) Ed8(i) Ed9(i) Ed10(i) Ed11(i) Ed12(i) Ed13(i) Ed14(i) Ed15(i) Ed16(i) Ed17(i) Ed18(i) Ed19(i) Ed20(i) Ed21(i) Ed22(i) Ed23(i) Ed24(i) Ed25(i) Ed26(i) Ed27(i) Ed28(i) Ed29(i) Ed30(i) Ed31(i) Ed32(i) Ed33(i) Ed34(i) Ed35(i) Ed36(i) Ed37(i) Ed38(i) Ed39(i) Ed40(i) Ed41(i) Ed42(i) Ed43(i) Ed44(i) Ed45(i) Ed46(i) Ed47(i) Ed48(i) Ed49(i) Ed50(i) Ed51(i) Ed52(i) Ed53(i) Ed54(i) Ed55(i) Ed56(i) Ed57(i) Ed58(i) Ed59(i) Ed60(i)];
end
NOW can u plz tel me how to do all this in a single loop?
i want to know how this all variables can be used to store the appropriate values... As in C- language its not happening here. if u know something about this plz help me... Thank you...
0 commentaires
Réponse acceptée
SL B
le 16 Mai 2013
Modifié(e) : SL B
le 16 Mai 2013
Why loop when you can just put it in a matrix? You are saying that Ed1 = [51.6149 27.1981 13.2580 2.3396] (this would be a row, but I'm assuming you have it in columns since you said you want the first value in each column of EdXX)
so assuming Edxx are column vectors:
Ed = [Ed1, Ed2, Ed3,.......,Ed60];
Then
Ved1 = Ed(1,:);
Ved2 = Ed(2,:);
Ved3 = Ed(3,:);
Ved4 = Ed(4,:);
1 commentaire
Plus de réponses (1)
David Sanchez
le 16 Mai 2013
for i=1:4
VEd(k) = [Ed1(i) Ed2(i) Ed3(i) Ed4(i) Ed5(i) Ed6(i) Ed7(i) Ed8(i) Ed9(i) Ed10(i) Ed11(i) Ed12(i) Ed13(i) Ed14(i) Ed15(i) Ed16(i) Ed17(i) Ed18(i) Ed19(i) Ed20(i) Ed21(i) Ed22(i) Ed23(i) Ed24(i) Ed25(i) Ed26(i) Ed27(i) Ed28(i) Ed29(i) Ed30(i) Ed31(i) Ed32(i) Ed33(i) Ed34(i) Ed35(i) Ed36(i) Ed37(i) Ed38(i) Ed39(i) Ed40(i) Ed41(i) Ed42(i) Ed43(i) Ed44(i) Ed45(i) Ed46(i) Ed47(i) Ed48(i) Ed49(i) Ed50(i) Ed51(i) Ed52(i) Ed53(i) Ed54(i) Ed55(i) Ed56(i) Ed57(i) Ed58(i) Ed59(i) Ed60(i)];
end
2 commentaires
Voir également
Catégories
En savoir plus sur Instrument Control Toolbox 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!