Azzera filtri
Azzera filtri

adding zero column to matrix

4 visualizzazioni (ultimi 30 giorni)
Sayanta
Sayanta il 21 Ago 2012
Hi All,
Currently I'm facing an error with a Matlab code.
In my problem I have Two matrix v and stateHit
v =
0.0044 0.1620 0.0272 0.0029 0.1610 0.6035 0.0151 0.0239
0.0044 0.1639 0.0275 0.0029 0.1606 0.6019 0.0150 0.0238
0.0043 0.1657 0.0279 0.0030 0.1601 0.6002 0.0150 0.0238
stateHit =
1 0 0 0
1 0 0 0
1 0 0 0
I want to do
difMatrix= v(1:length(stateHit),:) - cpustateHit;
??? Error using ==> minus Matrix dimensions must agree.
I want add zero columns to stateHit.
Could please give an example how can add zero columns to stateHit so that matrix dimension of v and stateHit became the same and I do that operations
difMatrix= v(1:length(stateHit),:) - cpustateHit;
many thanks in advance
SM

Risposta accettata

Titus Edelhofer
Titus Edelhofer il 21 Ago 2012
Hi,
if it's just that you want to enlarge "stateHit", you could do
if size(stateHit,2)<size(v, 2)
% v has more columns
stateHit(1, size(v,2)) = 0;
end
Titus

Più risposte (1)

Sayanta
Sayanta il 21 Ago 2012
Hi Titus,
Thanks you very much, it works nicely

Community Treasure Hunt

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

Start Hunting!

Translated by