Assigning a 2D matrix
Mostra commenti meno recenti
I have to create a 2D matrix, where the row number is unknown. I will have to find the row number.
Say, for i=1:5
for j=1:3
I want to create a 2D matrix with 2 columns, where the entries will be like [i j]
How should I write the code?
2 Commenti
Raj
il 31 Mag 2019
Your question is not at all clear. What exactly are you looking for? Can you give a better example?
Sariha Azad
il 31 Mag 2019
Risposta accettata
Più risposte (2)
Sariha Azad
il 1 Giu 2019
Simpler without a loop:
>> [X,Y] = ndgrid(1:3,1:5);
>> M = [X(:),Y(:)]
M =
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
1 4
2 4
3 4
1 5
2 5
3 5
1 Commento
Sariha Azad
il 1 Giu 2019
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!