Make a matrix from equation of vectors
Show older comments
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
Answers (1)
Andrei Bobrov
on 21 Nov 2015
Edited: Andrei Bobrov
on 21 Nov 2015
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 Comments
Jonas Pijnenburg
on 21 Nov 2015
Edited: Jonas Pijnenburg
on 21 Nov 2015
Andrei Bobrov
on 21 Nov 2015
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;
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!