Effacer les filtres
Effacer les filtres

Assign values(form of a row vector) with different sizes to a matrix(fixed size), row by row

2 vues (au cours des 30 derniers jours)
Let's say I have initialized a matrix with size m x n.
Now with a "for" loop, I assign the values row by row to this matrix, but the size of each row is different(all <= n).
This is currently giving me "Subscripted assignment dimension mismatch" error, what should I do if I want to do something like this?

Réponse acceptée

KSSV
KSSV le 8 Juin 2018
In that case you have two options.....
1. Option 1
Go for saving the data into cell .
m = 10 ;
iwant = cell(m,1) ;
for i = 1:m
iwant{i} = rand(randperm(100,1),1) ;
end
2. Option 2
Append NaN/ zeroes to extra data
m = 10 ;
n = 10 ;
iwant = NaN(m,n) ;
for i = 1:m
k = randperm(8,1) ;
iwant(i,1:k) = rand(1,k) ;
end
  1 commentaire
jin wang
jin wang le 8 Juin 2018
Thank you for the answer. If I choose option 2 but I don't know k, neither how the k can be calculated. Then how should I control the size like you did in the example?
iwant(i,1:k) = rand(1,k) ;
I will try len(), but it doesn't seem working

Connectez-vous pour commenter.

Plus de réponses (0)

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