Transposing matrix of elements added by for loop

조회 수: 2 (최근 30일)
Kevin Burg
Kevin Burg 2021년 6월 27일
댓글: DGM 2021년 6월 28일
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
Matt J
Matt J 2021년 6월 28일
I tried using transpose but that did not work
It doesn't seem possible that that would not work.
DGM
DGM 2021년 6월 28일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by