Combining matrices of different sizes
Afficher commentaires plus anciens
Hi
How can i combine two matrices of different sizes?
e.g,
x = [1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]; y = [1 2 3;4 5 6;7 8 9];
and
z = [x y]; % where z is also a matrix
how should i combine to x & y to get z?
I tried using the cat function but it gives an error:"Dimensions of matrices being concatenated are not consistent".
5 commentaires
Jan
le 23 Juil 2013
What does "combine" mean? How should the result look like? [x,y] cannot work, because the result must be a matrix again. And in matrices all columns and all rows must have the same length, respectively.
Syed
le 23 Juil 2013
Syed
le 23 Juil 2013
Gabriel Mühlebach
le 25 Juil 2016
Or you can use cell. For ex: a = [1,2;3,4]; b = ones(3,3); c = {a,b}; Like that you can put different matrix size in a same variable...
Réponse acceptée
Plus de réponses (1)
suresh s
le 23 Juil 2013
0 votes
hi Syed,
If the Size of both x and y matrix are same than only you can concatenated, otherwise we can't concatenate the matrix in Matlab
4 commentaires
Walter Roberson
le 20 Fév 2019
Perturabo comments to suresh s:
Unhelpful answer.
Walter Roberson
le 20 Fév 2019
Perturabo, I disagree. suresh s correctly answered the question in the form it was asked. What was asked for originally at the time was something that cannot be done, and telling someone that what they want to do cannot be done is being helpful.
It was not until slightly later that the original poster gave a sample output that permitted the question to be extended into something that could be solved.
Dmitriy Antselevich
le 27 Fév 2019
Ah yes, let's argue semantics on a Matlab forum.
People are not computers, if someone is asking a question they clearly have trouble with the concept and need the answer to be helpful not 1:1 correct.
Walter Roberson
le 27 Fév 2019
If someone asks to do X, then us telling them that X is not possible is correct and helpful. There is no requirement that we guess at all the different things that they might maybe have wanted to do.
I've done that, you know: taken a vague question and listed off pages and pages of things that the person might have meant, and how to do each of the possibilities, and the advantages and disadvantages of each of them and the contexts in which you might need each one. The response I got back was "Thanks." No vote, no acceptance of the my Answer, and in particular, no clarification of which one they had intended and no highlighting of what particular parts of what I said had especially clarified the situation for the person (so no feedback as to how my answer might have been improved). It took me hours to write up.
Other times, I have taken a few hours to write up responses to all the various things someone might have meant, only for the person to say the question was about something else completely that no-one could ever reasonably have perceived from what they had written.
I notice, Dmitriy, that you have posted no Answers at all. It is not clear that you have any significant experience in answering questions, deducing all of the various things that someone might mean, and explaining all of the possibilities.
Catégories
En savoir plus sur Point Cloud Processing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!