adding zero column to matrix

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by