Info
This question is locked. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error using stem X must be same length as Y.
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Sam Chak
2025년 4월 13일
이동: Sam Chak
2025년 4월 13일
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.
채택된 답변
Walter Roberson
2023년 4월 10일
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
추가 답변 (0개)
This question is locked.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!