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!