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
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.
Igor
Igor 2022 年 6 月 8 日
The size are Va1 = [400001,1], the same for Vb1 and Vc1

サインインしてコメントする。

採用された回答

Stephen23
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
Vout = 3×7
0.3928 0.3785 0.4278 0.6874 0.2438 0.4356 0.3693 0.4709 0.0741 -0.1156 -0.3263 -0.2120 0.0251 0.4612 0.1817 0.3943 0.5607 0.9821 0.4039 0.4885 0.1601
Checking:
1/3 * M * [Vin(1,1);Vin(1,2);Vin(1,3)]
ans = 3×1
0.3928 0.4709 0.1817

その他の回答 (1 件)

the cyclist
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 .*)
See this documentation for array vs matrix operations.
  2 件のコメント
Igor
Igor 2022 年 6 月 8 日
編集済み: Igor 2022 年 6 月 8 日
Even if the dimensions of Va1, Vb1 and Vc1 are [400001 1]?
Stephen23
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 ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by