Info
This question is locked. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Error using stem X must be same length as Y.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
TUAN SHARIFAH NUR FATIEHA
am 10 Apr. 2023
Locked: Rena Berman
am 23 Apr. 2025
fs = 100000; %sampling frequency
Ts = 1/fs;
Tstart = 22.7; % change to 22.6 for 2.4s time window
N = 2500001;%number of sample for fitting
T = N*Ts;
Electrical_Output_Torque = out.ScopeData12(:,2);
currenta=out.ScopeData7(:,2);
currentb=out.ScopeData7(:,3);
currentc=out.ScopeData7(:,4);
t1 = (1:length(currenta))*Ts;
figure(1)
plot(t1,currenta,'r')
title('Current Measurement in Time Domain');
xlabel('Time [s]');
ylabel('Current [A]');
grid on
currenta_sel = currenta(t1>=Tstart&t1<Tstart+T);
currenta_sel(1) = 0;
t1_sel = t1(t1>=Tstart&t1<Tstart+T);
figure(2)%selected time in current measurement (1.6s:4s)
plot(t1_sel,currenta_sel,'r')
title('Selected Time for the Current Measurement');
xlabel('Time [s]');
ylabel('Current [A]');
grid on
%%
ca_hanning = (currenta_sel .*hann(length(currenta_sel)))';
ca_hanning_fft = fftshift(fft(ca_hanning/length(ca_hanning)))';%2
caA_abs = abs(ca_hanning_fft);
caA_abs(1)= 0;
f1= (-fs/2):1/(T-Tstart):(fs/2);
figure(3);
stem(f1,caA_abs, 'r')
set(gca,'yscal','log')
grid on
title('4.6s, Hanning');
xlabel(' \it f (Hz)');
ylabel('|S(j\omega)| [A]');
xlim([0 100])
CaA_abs(1:2:end-1,:)= [];
f1(:,1:2:end-1)= [];
%%
figure(4);
stem(f1,CaA_abs, 'r')
set(gca,'yscal','log')
grid on
title('4kW motor- Hanning window');
xlabel(' \it f (Hz)');
ylabel('|S(j\omega)| (A)');
xlim([0 100])
6 Kommentare
Sam Chak
am 13 Apr. 2025
Verschoben: Sam Chak
am 13 Apr. 2025
You probably mean the similarity score. It is unnecessary to delete the question, as you can explore other alternatives.
Alternative #1:
Citing this forum post is likely the best option, as the original concept of the code came from you. However, you have edited the question. Consider restoring it if you choose this alternative. If you have nothing to hide, be transparent.
Alternative #2:
Edit the code in your thesis by renaming some variables. This can be a tedious task.
Akzeptierte Antwort
Walter Roberson
am 10 Apr. 2023
currenta=out.ScopeData7(:,2);
We are not given any information about what out is or size the various ScopeData* are. We can speculate that they are probably values output by Simulink . It is most common for Simulink scope blocks to be configured to remember only the last 10000 points. It is also common in Simulink for different parts of a model to be run at different intervals, so scope blocks in different parts of a model are not expected to have synchronized times (and so are not expected to have the same number of samples.)
currenta_sel = currenta(t1>=Tstart&t1<Tstart+T);
currenta_sel(1) = 0;
t1_sel = t1(t1>=Tstart&t1<Tstart+T);
You select a subset of the scope data anyhow, and you construct time vectors of similar length.
ca_hanning = (currenta_sel .*hann(length(currenta_sel)))';
ca_hanning_fft = fftshift(fft(ca_hanning/length(ca_hanning)))';%2
caA_abs = abs(ca_hanning_fft);
so caA_abs has size according to what was selected out of the current data.
f1= (-fs/2):1/(T-Tstart):(fs/2);
f1 is going to have size according to some fixed values. The length of f1 is not dependent on what size caA_abs turned out to be -- at least not in any direct way.
Because of cumulative floating point round-off error, you should not expect the colon operator to return the number of entries that it would if you were working algebraically. It is common for a colon operator to end up with one fewer entries than would be expected algebraically.
stem(f1,caA_abs, 'r')
We have no direct reason to expect that the sizes are going to match, and we have round-off-error reason to expect they might e different even if the rest of the calculations were correct.
You should probably be taking something like
f1 = linspace(-fs/2, fs/2, size(caA_abs,1));
1 Kommentar
Weitere Antworten (0)
This question is locked.
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!