Why does the "Matrix dimensions must agree" error persists?

조회 수: 1 (최근 30일)
Walter Fabián
Walter Fabián 2024년 5월 10일
편집: Hassaan 2024년 5월 10일
Good evening, I'm trying to plot an audiorecording with an Fs = 8KHz in appdesigner. I created a dropdown but idk why this error remains. I uploaded some images so u can understand me. I'd really apreciate it, its really important to figure it out. Thanks a lot.

답변 (2개)

sai charan sampara
sai charan sampara 2024년 5월 10일
Hello Walter,
When using "plot" in the format of "plot(ax,x,y)" the size of the variable "x" and "y" must be same. In your case make sure the size of the variables "t" and "y" are same. If they are not same you can try defining "t" such that it has the same length as "y".

Hassaan
Hassaan 2024년 5월 10일
편집: Hassaan 2024년 5월 10일
To give an initial idea:
% Example MATLAB code to plot an audio recording
% Sample rate
Fs = 8000; % 8 kHz
% Create a dummy audio signal (e.g., a sine wave for demonstration)
t = 0:1/Fs:1-1/Fs; % Create a time vector for 1 second of audio
frequency = 440; % Frequency of the sine wave (A4 pitch)
audioData = sin(2 * pi * frequency * t); % Generate audio data
% Plot the audio data
figure;
plot(t, audioData);
xlabel('Time (seconds)');
ylabel('Amplitude');
title('Audio Signal');
grid on;
% Dummy function to simulate dropdown callback in App Designer
function dropdownCallback(app, event)
frequency = str2double(app.DropDown.Value); % Get frequency from dropdown
% Recreate the audio signal with the new frequency
audioData = sin(2 * pi * frequency * t); % Generate new audio data
% Update the plot
plot(app.UIAxes, t, audioData); % Assume 'UIAxes' is your App Designer axis
xlabel(app.UIAxes, 'Time (seconds)');
ylabel(app.UIAxes, 'Amplitude');
title(app.UIAxes, ['Audio Signal at ', num2str(frequency), ' Hz']);
end
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by