Filter löschen
Filter löschen

Transposing matrix of elements added by for loop

2 Ansichten (letzte 30 Tage)
Kevin Burg
Kevin Burg am 27 Jun. 2021
Kommentiert: DGM am 28 Jun. 2021
I am creating a matrix with 38 unique entries. My for loop is creating a 1x38 matrix but I need it to be 38x1 for the operation I'm trying to perform. I tried using transpose but that did not work. How would I transpose this matrix so that I get each element added as a new row instead of a column? This is occuring on the Sol.RHS matrix
for i=1:inds.numinds
for j=1:inds.ind_dat(i).nconn
%
% gather the properties on both sides
%
jind=inds.ind_dat(i).conn_array(j).ind;
jsign=inds.ind_dat(i).conn_array(j).sign;
%
% indices for implicit contribution
%
ivmm=inds.numind*ind_scale_eq + (jind - 1) + 1;
%
% add in implicit and explicit terms - vapor
%
Sol.mat(ivmm,ivmm)=Sol.mat(ivmm,ivmm)+juns.jun_dat(jind).a*jsign/inds.ind_dat(i).volume;
Sol.RHS(ivmm)=transpose(Sol.RHS(ivmm)+juns.jun_dat(jind).a*jsign*inds.ind_dat(jind).vv/inds.ind_dat(i).volume);
end
end
  2 Kommentare
Matt J
Matt J am 28 Jun. 2021
I tried using transpose but that did not work
It doesn't seem possible that that would not work.
DGM
DGM am 28 Jun. 2021
How exactly did it not work? Since there really isn't any information here about the size of any of these variables, I have no idea what would happen. All anyone can go on is your assertion that one of them is 1x38 -- something that any troubleshooting should question if array size/orientation is not meeting expectations. You might want to provide enough data or pseudo-data such that your code constitutes a minimal working example of your problem.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by