I am trying to create a button in GUIDE that calculates the impedance modulo, but it gives me an error. Any help would be much appreciated!

1 view (last 30 days)
frekvencija = [1, 10, 50, 100, 200, 300, 500, 1000];
R = 100;
x1 = load('1Hz.mat');
x2 = load('10Hz.mat');
x3 = load('50Hz.mat');
x4 = load('100Hz.mat');
x5 = load('200Hz.mat');
x6 = load('300Hz.mat');
x7 = load('500Hz.mat');
x8 = load('1000Hz.mat');
Um = [x1, x2, x3, x4, x5, x6, x7, x8];
struja = Um/R; %moduo struje
strujafft=abs(fft(struja)); %brza furijeova transformacija u frekvencijskom
[struja_max_amp, Index]= max(strujafft); %uzimamo maksimalnu amplitudu, index je na kom mestu se nalazi
struja_maxt = struja_max_amp/(length(strujafft)/2); %amplituda izracunate struje u vremenskom domenu
moduo = 1/struja_maxt; %moduo |Z(s)| , napon = 1V, zato je 1/struju;
axes(handles.axes3)
plot(frekvencija, moduo)
w = 2*pi*frekvencija;
M = zeros(length(w), 3);
O = zeros(length(moduo), 1);
for i = 1:length(Z)
M(i, :) = [1, w(i)^2, -w(i)^2*moduo(i)^2];
O(i, :) = [moduo(i)^2];
end
N =((M'*M)^(-1))*M'*O;
%A = R1+R2; B = R1*R2*C; D = R2*C;
A=sqrt(N(1));
B=sqrt(N(2));
D=sqrt(N(3));
R1 = A - R2;
R2 = D/C;
C = B/R1*R2;
guidata(hObject, handles);
The following is the full error I receive:
Error using /
Arguments must be numeric, char, or logical.
Error in domaci1>pushbuttonIscrtaj_Callback (line 290)
struja = Um/R; %moduo struje

Answers (1)

Cris LaPierre
Cris LaPierre on 3 Nov 2022
Um is an array of structures. This is likely the source of your error. To use "/", the arguments must be numeric, char, or logical. I don't know what the variables names are in your mat files, but assuming they are the same as your intended variable names, you need to do something like this
% Assumes your field names are the same as structure name
% If not, adjust the field name to match your data
Um = [x1.x1, x2.x2, x3.x3, x4.x4, x5.x5, x6.x6, x7.x7, x8.x8];

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by