Error usin .* Too many output arguments. How to save three variables at the same time in a loop?
1 view (last 30 days)
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
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)];
HOW CAN I SOLVE THIS??
Stephen23 on 8 Jun 2022
Edited: Stephen23 on 8 Jun 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
1/3 * M * [Vin(1,1);Vin(1,2);Vin(1,3)]
More Answers (1)
the cyclist on 8 Jun 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)]
[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.