フィルターのクリア

What is wrong with: [betta;del​ta;gamma]=​inv([ab ab_cd -cd])*[C-A];

1 回表示 (過去 30 日間)
mb12345
mb12345 2018 年 10 月 25 日
編集済み: John D'Errico 2018 年 10 月 30 日
Hi
[betta;delta;gamma]=inv([ab ab_cd -cd])*[C-A];
betta, delta and gamma should be scalars.
ab, ab_cd, cd, C and A are column vectors with 3 rows (e.g. [1;2;3]).
I want that
betta = leftvektor(1)
delta = leftvektor(2)
gamma = leftvektor(3)
Matlab shows an error but I am not sure why. Does anyone knows why?

採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 30 日
編集済み: Bruno Luong 2018 年 10 月 30 日
You cannot capture elements of array on the lhs directly to variables, you have to split it:
x = inv([ab ab_cd -cd])*[C-A];
betta = x(1); % beta is better me think
delta = x(2);
gamma = x(3);

その他の回答 (1 件)

John D'Errico
John D'Errico 2018 年 10 月 30 日
編集済み: John D'Errico 2018 年 10 月 30 日
Why? This is because what you want to do is not valid in MATLAB. You can want for anything. If wishes were horses, beggars would ride.
You cannot split a result as a vector into multiple arguments.
Can you solve the problem? Well, yes. Sigh. Write a little helper function that will take a vector, and automatically split it into scalars.
function varargout = split2scalars(Vec)
% splits a vector of length n into n scalars
n = numel(Vec);
varargout = mat2cell(Vec(:),ones(n,1),1);
So ...
[Vx,Vy,Vz] = split2scalars(1:3)
Vx =
1
Vy =
2
Vz =
3
Use it as:
[betta;delta;gamma] = split2scalars(inv([ab ab_cd -cd])*[C-A]);

Community Treasure Hunt

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

Start Hunting!

Translated by