Why does the "Matrix dimensions must agree" error persists?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (2)
sai charan sampara
el 10 de Mayo de 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".
0 comentarios
Hassaan
el 10 de Mayo de 2024
Editada: Hassaan
el 10 de Mayo de 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.
0 comentarios
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!