How to save output in different column for each loop

8 Ansichten (letzte 30 Tage)
Chuanjung Lin
Chuanjung Lin am 26 Jan. 2018
Good day everyone, I have wrote a for loop, and code as following:
Vg=[]
for i=0:2:10
y=Rawdata(:,2+i);
y_data=find(y>0.9e-9 & y<1.8e-9)
Vg=[Vg; x(y_data)]
end
I want to save the result in different column instead of single column. How to achieve it? Because it's single column now.....
Thank you.

Antworten (1)

Harish Ramachandran
Harish Ramachandran am 1 Feb. 2018
I am not sure what x(y_data) is.
However, I will try to give you a trivial example which you can probably use to scale for your problem. Below is a piece of code to append 5*i based on each iteration i of the for loop.
V = [];
for i=1:10
x = 1:5
V = [V ; i.*x'];
end
This results in the resultant V being a vector of 50x1 which I believe is similar to your case. On making the required change (as in the code below) you will be able to save the result to a different column.
V = [];
for i=1:10
x = 1:5
V = [V i.*x'];
end
Now V is a 5x10 double vector.
V =
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
Hope this helps.

Kategorien

Mehr zu 循环及条件语句 finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!