adding zero column to matrix

1 回表示 (過去 30 日間)
Sayanta
Sayanta 2012 年 8 月 21 日
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

採用された回答

Titus Edelhofer
Titus Edelhofer 2012 年 8 月 21 日
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

その他の回答 (1 件)

Sayanta
Sayanta 2012 年 8 月 21 日
Hi Titus,
Thanks you very much, it works nicely

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by