How can i convert a matrix to a specific feature with matlab

1 view (last 30 days)
Hello everybody.
I need desperately your help as I am not very familiar with Matlab. Let assume that I have two matrixes for instance
a=[205;165;175;165;135]
b=[25;25;55;65;65] (dimension 5x1 each one)
What I want to do is to take the numbers from each row of the matrixes a and b and have a new one with a specific feature like
c=[205 25,165 25,175 55,165 65,135 65]
In more general I want to have a new matrix
C=[a11 b11,a21 b21,a31 b31,…aj1 bj1,…ai1 bi1]
if the a and b matrixes have ix1 dimension . Also bear in mind that C matrix has a specific feature as I have mentioned so far. What I mean with this is between some aj1 and bj1 there is a space gap and each pair let say a21 b21 and a31 b31 is separated by a comma (,).
Thanks everybody for your help

Answers (2)

Guillaume
Guillaume on 18 Dec 2015
Spaces, commas, semicolons are all syntactic elements that are not part of the data that is stored in a matrix. It's only used as for display and input. As far as matlab is concerned a matrix is just a bunch of numbers.
Therefore, your specific feature is not possible. spaces and commas mean the same thing when you input a matrix and matlab displays them both as space. semicolons mark the end of a row, when you input a matrix and matlab displays that as a new line.
It sounds like you're confusing the display of a matrix with the content. As said, a matrix is just numbers. spaces and commas do not feature into it.
  1 Comment
Walter Roberson
Walter Roberson on 23 Dec 2015
Ang Vas replied in a duplicate question:
is any other alternative way to do this feature with numbers and commas? Actually what I am trying to do is to have the numbers in such row as to be able to import them in Inkscape

Sign in to comment.


Walter Roberson
Walter Roberson on 23 Dec 2015
As you want this for display (output) purposes,
t = sprintf('%g %g,', [a,b].');
c = [ '[', t(1:end-1), ']' ]; %trim trailing comma
Now you can output the string c

Products

Community Treasure Hunt

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

Start Hunting!