I need to create a matriz since two different?

Hi i'm trying to build a matrix with the following data:
disp(C)
9.9176 3.4750
20.6735 936.0956
15.3217 592.1325
11.8539 128.6507
12.1579 430.5301
13.2333 267.0387
16.3886 762.0092
and the frecuency of every row
disp(V)
5191 1
575 1
455 1
849 1
665 1
618 1
407 1
But when i do the following,
a=[V; C];
disp(a)
5.1910 0.0010
0.5750 0.0010
0.4550 0.0010
0.8490 0.0010
0.6650 0.0010
0.6180 0.0010
0.4070 0.0010
0.0099 0.0035
0.0207 0.9361
0.0153 0.5921
0.0119 0.1287
0.0122 0.4305
0.0132 0.2670
0.0164 0.7620
This is wrong, because i expect a 3 by 7 matriz. What do i need to do?

Antworten (3)

Massimo Zanetti
Massimo Zanetti am 10 Okt. 2016

1 Stimme

Try
a=[V, C];

1 Kommentar

I still have wrong values
5.1930 0.0010 0.0099 0.0035
0.4520 0.0010 0.0156 0.6014
0.8550 0.0010 0.0119 0.1295
0.5700 0.0010 0.0207 0.9368
0.6720 0.0010 0.0121 0.4363
0.6300 0.0010 0.0133 0.2706
0.3880 0.0010 0.0164 0.7682

Melden Sie sich an, um zu kommentieren.

Guillaume
Guillaume am 10 Okt. 2016

1 Stimme

I assume you mean a 7 (rows) by 3 (columns) matrix, although I have no idea why just 3 and not 4 columns.
The semicolon ; concatenates vertically, so matlab has done exactly what you asked. If you want to concatenate horizontally, use a comma , or a space.
a = [V, C]; %or [V C], I recommend using a comma
I also recommend you go through the getting started tutorial
Marc Jakobi
Marc Jakobi am 10 Okt. 2016

0 Stimmen

I assume you want:
a = [V(:,1), C];

4 Kommentare

No Marc, i want the real values, now appears wrong values.
0.4070 0.0164 0.7620
5.1910 0.0099 0.0035
0.5750 0.0207 0.9361
0.6650 0.0122 0.4305
0.8490 0.0119 0.1287
0.6180 0.0132 0.2670
0.4550 0.0153 0.5921
Marc Jakobi
Marc Jakobi am 10 Okt. 2016
Bearbeitet: Marc Jakobi am 10 Okt. 2016
If you look closely, it says:
1.0e+03 *
5.1910 0.0099 0.0035
0.5750 0.0207 0.9361
0.4550 0.0153 0.5921
0.8490 0.0119 0.1287
0.6650 0.0122 0.4305
0.6180 0.0132 0.2670
0.4070 0.0164 0.7620
So each value is multiplied by 1000. Try typing in
a = [V(:,1), C];
disp(num2str(a))
5191 9.9176 3.475
575 20.6735 936.0956
455 15.3217 592.1325
849 11.8539 128.6507
665 12.1579 430.5301
618 13.2333 267.0387
407 16.3886 762.0092
Guillaume
Guillaume am 10 Okt. 2016
Bearbeitet: Guillaume am 10 Okt. 2016
or better change your displayed format, e.g:
format shortg
As I said in my answer, you really need to go through getting started tutorial. All of this is really really basic matlab.
Steven Lord
Steven Lord am 10 Okt. 2016
Or instead of using num2str, change the display format as described in the responses to this other Answer post from Tony.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 10 Okt. 2016

Kommentiert:

am 10 Okt. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by