How to save output in different column for each loop

조회 수: 2 (최근 30일)
Chuanjung Lin
Chuanjung Lin 2018년 1월 26일
답변: Harish Ramachandran 2018년 2월 1일
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.

답변 (1개)

Harish Ramachandran
Harish Ramachandran 2018년 2월 1일
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.

카테고리

Help CenterFile Exchange에서 循环及条件语句에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!