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!