How to use for loop correctly and indexing my result?
1 次查看(过去 30 天)
显示 更早的评论
a = [1 1 1 0 0 0 0 1 0 1 0 1 1 0 0 1] ;
b = [1 1 1 0 1 0 0 0 1 1 1 0 0 0 0 1] ;
S = [a, a, a, a, a, a, a, a, a ,a;b, b, b, b, b, b, b, b, b, b];
x1 = S(1:1,:);
x2 = S(2:2,:);
L = 3;
for i = 3:160
x11 = [x1(i),x2(i)]
x12 = [x1(i-1),x2(i-1)]
x13 = [x1(i-L+1),x2(i-L+1)]
x14 = [1]
X1 = [x11 x12 x13 x14]
end
Hi this is my code. After I run it, it display the answer for x11, x12, x13, x14, and X1 directly with i = 3 to 160, a total of 158 sets of results. How to code such that i want to select my 3rd result to show only?
0 个评论
回答(1 个)
madhan ravi
2020-5-31
Use ; at the end of each line inside the loop.
X1(3,:) % after the loop
6 个评论
madhan ravi
2020-5-31
Please illustrate with a short example with an expected result, so it's easy to understand the main goal.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!