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

1 vue (au cours des 30 derniers jours)
Walter Fabián
Walter Fabián le 10 Mai 2024
Modifié(e) : Hassaan le 10 Mai 2024
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.

Réponses (2)

sai charan sampara
sai charan sampara le 10 Mai 2024
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 le 10 Mai 2024
Modifié(e) : Hassaan le 10 Mai 2024
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.

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by