Wrong with matrix dimensions
이전 댓글 표시
I'm only a beginner when it comes to MatLab and would therefor appreciate some help.
This is my code:
clc
clear
close all
load geiger.txt;
load temperatur.txt; %hämtar filerna med relevant data
i = geiger(:,4);
j = i*4500;
t1 = geiger(:,1);
x = [1:120]; %omvandling till rätt vektor
tidW = (x-1)*10;%omvandling till rätt enhet
t2 = temperatur(:,1);
tidT = (t2-1)*10;
T = temperatur(:,4)+273;
acc(1) = j(1);
for h = 2:length(j) %lägger ihop pulserna från geigermätaren
acc(h)= acc(h-1)+j(h);
end
p1 = polyfit(tidW,acc,3); %anpassar polynom till W(t)
pv1 = polyval(p1,tidW); %gör om värdena med polynomet som grund
pd1 = polyder(pv1); %deriverar polynomet
p = polyval(pd1, tidW)
p2 = polyfit(t2,T,2); %anpassar polynomet T(t)
pv2 = polyval(p2,t2);
pd2 = polyder(p2);
p2 = polyval(pd2,t2);
PH = 10*4190*p2;
e = PH./p;
plot(tidW,acc,'r')
hold on
plot(tidW, pv1,'b')
figure(2)
plot(t2, T,'r')
hold on
plot(t2,pv2,'b')
figure(3)
plot(t2,e)
And MatLab tells me that there's wrong with the matrix dimensions (matrix dimensions must agree)
This is due on tuesday and I'm getting a bit stressed out! All sort of help is highly appreciated!
채택된 답변
추가 답변 (2개)
Walter Roberson
2011년 2월 18일
0 개 추천
Which line is it complaining about, and what are the sizes of the variables involved?
I notice that most of your variables are column vectors. However, because your acc array does not have a preallocated size, it will default to being a row vector. There are certainly cases where the difference between row vector and column vector could cause problems.
Matt Tearle
2011년 2월 18일
Aside: you can replace
acc(1) = j(1);
for h = 2:length(j) %lägger ihop pulserna från geigermätaren
acc(h)= acc(h-1)+j(h);
end
with
acc = cumsum(j);
Oh yeah baby!
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!