Problem When Concatenating 2 Arrays [Help]
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Roger Stafford
le 9 Avr 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!