i would like to use the command reshape to convert a vector v=11:99 to a matrix (9x9), how can i do this, can anyone help me ?

 Réponse acceptée

Birdman
Birdman le 21 Nov 2017

0 votes

You can not do it when v=11:99.
If you want to convert to 9x9 matrix, then you need to have 81 elements in your vector, with this you have 89. If you define it as v=11:91, then the following command will do what you want.
v=reshape(v,9,9)

13 commentaires

diadalina
diadalina le 21 Nov 2017
thank you Mr,cvklpstunc, for your answer.
Birdman
Birdman le 21 Nov 2017
You are welcome, if it is helpful, you can accept the answer.
diadalina
diadalina le 21 Nov 2017
have you another way to create this matrix please ?
Birdman
Birdman le 21 Nov 2017
As I said before, 89 is a prime number and the only way to reshape it is either 89x1 or 1x89 vector. There is no other way.
diadalina
diadalina le 21 Nov 2017
i want a way without using the loop for .
Birdman
Birdman le 21 Nov 2017
Okay, you do not need for loop anyway, but you have 89 elements, either change it or you can not do anything with it.
diadalina
diadalina le 21 Nov 2017
Modifié(e) : diadalina le 21 Nov 2017
i can do it like this, A=[11:19;21:29;31:39;41:49;51:59;61:69;71:79;81:89;91:99], but i want a way more easier than this.
Birdman
Birdman le 21 Nov 2017
But you skip 20,30,40,...,90 in this case
diadalina
diadalina le 21 Nov 2017
no, that is the result , that i want, i have this way also: l=11:19; A=[l;l+10;l+20;l+30;l+40;l+50;l+60;l+70;l+80]; but i think , there is another way more easier than this.
Birdman
Birdman le 21 Nov 2017
But v=11:99 includes 20,30,40,...,90 so you need to know what you ask.
diadalina
diadalina le 21 Nov 2017
tha is the result, that i had wanted. A =
11 12 13 14 15 16 17 18 19
21 22 23 24 25 26 27 28 29
31 32 33 34 35 36 37 38 39
41 42 43 44 45 46 47 48 49
51 52 53 54 55 56 57 58 59
61 62 63 64 65 66 67 68 69
71 72 73 74 75 76 77 78 79
81 82 83 84 85 86 87 88 89
91 92 93 94 95 96 97 98 99
Birdman
Birdman le 21 Nov 2017
v=11:99;
IND=find(mod(v,10)==0);
v(IND)=[];
v=reshape(v,9,9)
diadalina
diadalina le 21 Nov 2017
that's exactly , what i want, thank you very much.

Connectez-vous pour commenter.

Plus de réponses (1)

KL
KL le 21 Nov 2017

0 votes

Simpler with just one line,
bsxfun(@plus,1:9,(10:10:90).')

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by