Error usin .* Too many output arguments. How to save three variables at the same time in a loop?
1 回表示 (過去 30 日間)
古いコメントを表示
I need to do the following Clarke transform of a three-phase voltage signal, as follows:
I'm having the following problem:
this is the code:
clear all; close all; clc;
N = 32; a = 1;
arq = load ('MODELS.1');
t = arq(:,1);
Va1 = arq(:,2); Vb1 = arq(:,3); Vc1 = arq(:,4); %tensoes BUS1
Ia1 = arq(:,5); Ib1 = arq(:,6); Ic1 = arq(:,7); %correntes BUS1
% Va2 = arq(:,8); Vb2 = arq(:,9); Vc2 = arq(:,10); %tensoes BUS2
% Ia2 = arq(:,11); Ib2 = arq(:,12); Ic2 = arq(:,13); %correbtes BUS2
disp('Sinal carregado')
Vbeta1=zeros(length(t),3);V01=Vbeta1;Valpha1=V01;
for a = 1:size(t,1)
[V01(a,1) V01(a,2) V01(a,3)] = [1 1 1;2 -1 -1;0 sqrt(3) -sqrt(3)].*[Va1(a);Vb1(a);Vc1(a)];
end
HOW CAN I SOLVE THIS??
2 件のコメント
James Tursa
2022 年 6 月 8 日
What are the sizes of all the variables involved? You might be able to do this with some combination of matrix multiply and not need any loops.
採用された回答
Stephen23
2022 年 6 月 8 日
編集済み: Stephen23
2022 年 6 月 8 日
Do not use separate variables with names Va, Vb, Vc, etc. The name MATLAB comes from "MATrix LABoratory". MATLAB is designed to work efficiently and simply with matrices. Your task is perfect for using matrices, rather than lots of separate variables. You should use matrices.
Do not use a loop. The operation you need is very simple matrix multiplication. Using a loop is much more complex.
Vin = rand(7,3); % much better in one matrix, i.e. arq(:,2:4)
M = [1,1,1;2,-1,-1;0,sqrt(3),sqrt(3)];
Vout = M*Vin.'/3
Checking:
1/3 * M * [Vin(1,1);Vin(1,2);Vin(1,3)]
その他の回答 (1 件)
the cyclist
2022 年 6 月 8 日
Given the image of the calculation you posted, I think you want matrix multiplication, not elementwise multiplication:
[V01(a,1) V01(a,2) V01(a,3)] = [1 1 1;2 -1 -1;0 sqrt(3) -sqrt(3)]*[Va1(a);Vb1(a);Vc1(a)]
instead of
[V01(a,1) V01(a,2) V01(a,3)] = [1 1 1;2 -1 -1;0 sqrt(3) -sqrt(3)].*[Va1(a);Vb1(a);Vc1(a)]
(Note the use of * instead of .*)
2 件のコメント
Stephen23
2022 年 6 月 8 日
"Even if the dimensions of Va1, Vb1 and Vc1 are [400001 1]?"
No.
This code contains exactly the same bug as your question, namely trying to return three outputs from an operation which only returns one output. Whether you use array or matrix multiplication makes no difference to that bug.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!