How to store index values in the form of arrays using for loop?
Mostra commenti meno recenti
Hello Everyone
Can you please tell me how to save indes values of the following code from the for loop?
rng default
M = zeros(randi([3 6]),randi([3 6]))
[u,v] = size(M)
for i = 1:u
for j = 1:v
ind1(i) = i;
ind2(j) = j;
indices = [ind1(i),ind2(j)]
end
end
I want to store the values in the form of two colums and m*n rows.
Thank you
Risposta accettata
Più risposte (1)
KALYAN ACHARJYA
il 1 Giu 2020
Modificato: KALYAN ACHARJYA
il 1 Giu 2020
Cell array
rng default
M = zeros(randi([3 6]),randi([3 6]))
[u,v] = size(M)
indices=cell(u,v);
for i = 1:u
for j = 1:v
ind1(i) = i;
ind2(j) = j;
indices{i,j}=[ind1(i),ind2(j)];
end
end
2 Commenti
SAURAV SANKHE
il 1 Giu 2020
madhan ravi
il 1 Giu 2020
You don’t preallocate properly do you?
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!