Problem When Concatenating 2 Arrays [Help]

2 次查看(过去 30 天)
Dear Friends,
I am facing a problem when concatenating 2 arrays. Let's say that I have variable A, which is a 500x2 double (filled by integers), and variable B which is a 500x1 double (filled by real numbers).
A =
23 12
25 10
7 30
B =
0.18237
0.23872
0.45657
If I use :
C = horzcat(A, B);
or
C = [A B];
Matlab would show a result such as :
.
0.0000 0.0000 0.1635
0.0000 0.0000 0.5378
0.0000 0.0000 0.1029
0.0000 0.0000 0.1207
The first two column would be zero.
Anyone have an idea why this is happening?
Thanks in advance

采纳的回答

Roger Stafford
Roger Stafford 2013-4-9
The problem is not in the concatention; it is in the display of the results. Apparently all the entries from A that are shown are smaller in magnitude than 0.00005 so that when rounded to four places you see a zero displayed. Try using "format long" before displaying the results. Or better still use floating point formatting provided by fprintf to allow each entry to be displayed in accordance with its own magnitude. Your first row might then look something like this:
1.111111111111111e-10 -2.222222222222222e-11 1.634987654321234e-1
Note: I am responding here to your original posting. As you have now edited it the results look impossible. You had better check that again.
  1 个评论
ElevenFourth
ElevenFourth 2013-4-9
Thank you very much for your answer Mr. Stafford. I just have to adjust the format, and actually nothing happens with the calculation.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by