MATLAB Answers

Selecting specific columns in a for loop

조회 수: 16(최근 30일)
Lui
Lui 11 Jul 2020 11:34
편집: madhan ravi 11 Jul 2020 20:44
Hi everyone,
I would like to select to multiply integers between 401:500 with a matrix as shown in the code below
for j=401:500
Meas_Load{j,1}= RLoad2 - j.*RPVR;
end
My expectation is that the variable Meas_Load is a cell if dimension 100 by 1. Unfortunately the resulting dimension is 500 by 1. How can I achieve a 100 by 1 cell in this loop? Thanks

  댓글 수: 2

KSSV
KSSV 11 Jul 2020 11:38
What is size of RLoad2, RPVR?
Lui
Lui 11 Jul 2020 20:32
Rload2 has 1000 by 100 and RPVR has 1000 by 1.
Apart from their length, does it matter? All the data sets have the same length. The only difference is in the number of columns.

Sign in to comment.

채택된 답변

madhan ravi
madhan ravi 11 Jul 2020 12:08
편집: madhan ravi 11 Jul 2020 20:44
jj = 401:500;
Meas_Load = cell(numel(jj), 1);
for k = 1:numel(jj)
Meas_Load{k}= Rload2 - jj(k)*RPVR;
end
celldisp(Meas_Load)
Or simply
Meas_Load = Rload2 - reshape(jj, 1, 1, []) .* RPVR; % 3D matrix

  댓글 수: 0

Sign in to comment.

추가 답변(0개)


Translated by