Info
This question is closed. Reopen it to edit or answer.
How to create for loop for the below case
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Aquatris
on 23 Aug 2018
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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!