Filter löschen
Filter löschen

Problem When Concatenating 2 Arrays [Help]

2 Ansichten (letzte 30 Tage)
ElevenFourth
ElevenFourth am 8 Apr. 2013
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

Akzeptierte Antwort

Roger Stafford
Roger Stafford am 9 Apr. 2013
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 Kommentar
ElevenFourth
ElevenFourth am 9 Apr. 2013
Thank you very much for your answer Mr. Stafford. I just have to adjust the format, and actually nothing happens with the calculation.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by