Hi guys!
I want to make a matrix out of my equation with two variables. To do this, i made two vectors and make it run trough a if loop. I googled the error and I tried to do it in different ways, but after two hours I thought i'd ask my first question on these forums :)
clear
alpha = 1:1:10
beta = 2:2:20
j=1;
while j<10
y(j) = 3*beta(j)-2.*alpha
j=j+1;
end
This gives the error: 'Subscripted assignment dimension mismatch.' (in the line of y(j)). When I change it to y{j}, to make it a set, everything does work. The idea should work I think, but I can't figure out how to code it.
Thanks! J

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 11월 21일
편집: Andrei Bobrov 2015년 11월 21일

0 개 추천

alpha = 1:1:10;
beta = 2:2:20;
solution:
y = bsxfun(@minus,3*beta',2*alpha);
or
m = numel(alpha);
n = numel(beta);
y = zeros(n,m);
b = beta(:);
for jj = 1:m
y(:,jj) = 3*b-2.*alpha(jj);
end

댓글 수: 2

Jonas Pijnenburg
Jonas Pijnenburg 2015년 11월 21일
편집: Jonas Pijnenburg 2015년 11월 21일
Thank you for your quick reply! Your second solution gives one row with only zeroes so I guess something went wrong there. I types n+1 at the while and now it works :)
Since the actual formula in my homework is this a bit complicated I think i won't be able to make it with the bsxfun function.
zeta{j} = (((mu*Fzf)*(1 - lapda(j)).*(1 - (Er*(sqrt((lapda(j).^2) + (tan(alpha)).^2)))))./(2*sqrt(((Cxf.*lapda(j)).^2)+((Cyf.*tan(alpha)).^2))));
variant
lapda = lapda(:)';
l2 = lapda.^2;
ta2 = tan(alpha(:)).^2;
a = bsxfun(@times,(1 - lapda),1 - Er*sqrt(bsxfun(@plus,l2,ta2)));
b = sqrt(bsxfun(@plus,Cxf.^2.*l2,Cyf.^2.*ta2));
zeta = mu*Fzf/2*a./b;

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

질문:

2015년 11월 21일

편집:

2015년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by