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

2 次查看(过去 30 天)
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

回答(2 个)

Guillaume
Guillaume 2015-12-18
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 个评论
Walter Roberson
Walter Roberson 2015-12-23
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

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2015-12-23
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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by