Effacer les filtres
Effacer les filtres

Transposing matrix of elements added by for loop

2 vues (au cours des 30 derniers jours)
Kevin Burg
Kevin Burg le 27 Juin 2021
Commenté : DGM le 28 Juin 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 commentaires
Matt J
Matt J le 28 Juin 2021
I tried using transpose but that did not work
It doesn't seem possible that that would not work.
DGM
DGM le 28 Juin 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by