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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1025710/image.png)
I'm having the following problem:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1025715/image.png)
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!