Why does the "Matrix dimensions must agree" error persists?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
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".
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!