Effacer les filtres
Effacer les filtres

Read vectors into a matrix of NaNs??

1 vue (au cours des 30 derniers jours)
Chelsey
Chelsey le 5 Oct 2011
I have a large 25x25 matrix full of "NaN". I created it so that I could put several different 1-dimensional arrays of different lengths into one matrix together. But now I am having issues replacing the NaNs with the elements of the individual arrays.
For example, I have the big matrix "SalMat"
SalMat = repmat({NaN},25,25);
And I would like for sal01 to be the new first column of SalMat:
sal01 =
26.7762
26.7769
26.7773
26.7781
26.8047
27.0839
28.6000
30.5953
32.4578
33.2129
34.0983
34.4630
34.6466
34.6961
34.7120
34.7924
35.4376
35.5727
This would then be repeated with sal02,sal03,....sal25 inserted into the 25 columns of SalMat.
Any suggestions???

Réponse acceptée

Sean de Wolski
Sean de Wolski le 5 Oct 2011
repmat({nan},blah)
will replicate a cell of nan. You don't want cells ( doc cell, for more info). You want a regular matrix:
Salmat = nan(25); %same as repmat(nan,25,25);
Then do the insertions. Also read this FAQ4.6
  1 commentaire
Chelsey
Chelsey le 5 Oct 2011
Thank you!

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 5 Oct 2011
SalMat = nan(25)
c = arrayfun(@(x)randi(randi(123),randi(25),1),1:25,'un',0)
for j1 = 1:size(SalMat,2)
SalMat(1:numel(c{j1}),j1) = c{j1};
end

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by