Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How to create for loop for the below case
조회 수: 1 (최근 30일)
이전 댓글 표시
I have the variables
P=[X, Y];Q=-C+P(2);C=0.5;
Where, X takes the value of (1,1) and Y takes the value of (2,1) from the data(which is given below). I have to run a loop to calculate Q for all the values from the data in the corresponding way(1,2)&(2,2)....(1,n)(2,n). I tried using cellfun(where i used, num2cell to change two rows into one single row with the cell values) but am not getting the required output. Kindly help me
data =[1 2 3 4 5 6;2 3 5 8 9 7];
[rows, columns]=size(data);
댓글 수: 0
답변 (1개)
Aquatris
2018년 8월 23일
First of all, your code does not look like it is in order. You define C after you calculate Q? You do not use X in any calculation?
Regardless, the thing you want to do do not require for loop.
data =[1 2 3 4 5 6;2 3 5 8 9 7];
C = 0.5;
X = data(1,:);
Y = data(2,:);
Q = -C + Y;
Q will be a vector the size of Y and Q(n) represents the value when Y = data(2,n). If you have X somewhere in the calculation, you can add it as such;
Q = -C + X.*Y - X + X.^2;
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!