Make a matrix from equation of vectors
이전 댓글 표시
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
2015년 11월 21일
편집: Andrei Bobrov
2015년 11월 21일
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
2015년 11월 21일
편집: Jonas Pijnenburg
2015년 11월 21일
Andrei Bobrov
2015년 11월 21일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!