Error usin .* Too many output arguments. How to save three variables at the same time in a loop?

1 visualización (últimos 30 días)
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')
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)];
  2 comentarios
James Tursa
James Tursa el 8 de Jun. de 2022
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.

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23 el 8 de Jun. de 2022
Editada: Stephen23 el 8 de Jun. de 2022
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
1/3 * M * [Vin(1,1);Vin(1,2);Vin(1,3)]
ans = 3×1
0.3928 0.4709 0.1817

Más respuestas (1)

the cyclist
the cyclist el 8 de Jun. de 2022
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 comentarios
Igor el 8 de Jun. de 2022
Editada: Igor el 8 de Jun. de 2022
Even if the dimensions of Va1, Vb1 and Vc1 are [400001 1]?
Stephen23 el 8 de Jun. de 2022
"Even if the dimensions of Va1, Vb1 and Vc1 are [400001 1]?"
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.

Iniciar sesión para comentar.


Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by