Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to create for loop for the below case

1 Ansicht (letzte 30 Tage)
vigneshwaran Loganathan
vigneshwaran Loganathan am 21 Aug. 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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);

Antworten (1)

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

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by