Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to create for loop for the below case

1 回表示 (過去 30 日間)
vigneshwaran Loganathan
vigneshwaran Loganathan 2018 年 8 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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);

回答 (1 件)

Aquatris
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;

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by