I get Subscripted assignment dimension mismatch.

1 回表示 (過去 30 日間)
Gonzalo Reina
Gonzalo Reina 2016 年 10 月 26 日
コメント済み: Gonzalo Reina 2016 年 10 月 26 日
I get Subscripted assignment dimension mismatch when running this program.I just want the program to ask the user the number of sinwaves he wants to plot and also the frequency and amplitude of each
clear
clc
x = input('Please input the number of sinewaves that you want to be plotted ');
T = 1:10;
for n = 1:x
f(n) = input('Please input the frequency of the wave');
A(n) = input('Please input the amplitude of the wave');
wave(n) = (A(n))*sin(2*pi*(f(n))*T);
plot(T,wave(n),'b')
grid on
hold on
xlabel('Time')
ylabel('Amplitude')
title('Sinwave')
end

採用された回答

Mischa Kim
Mischa Kim 2016 年 10 月 26 日
編集済み: Mischa Kim 2016 年 10 月 26 日
Use instead
wave(n,:) = (A(n))*sin(2*pi*(f(n))*T);
plot(T,wave(n,:),'b')
You also might want to think about pre-allocating A and f.
What exactly are you trying to accomplish? I am asking because there might be more user-friendly ways of getting the values for those two vectors.
  1 件のコメント
Gonzalo Reina
Gonzalo Reina 2016 年 10 月 26 日
That enough user friendly for what I am trying to do. It is just a simple program to plot graphs. Why did you change that? pd:I'm a noob for matlab

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by