How do I output the values of a function in a vector string to plot a graph?

2 ビュー (過去 30 日間)
Red
Red 2021 年 10 月 11 日
コメント済み: Mathieu NOE 2021 年 11 月 5 日
A = 1;
df = 100000;
F = df/4;
n = 2^3;
t = [0:n-1]/df;
s = A*sin(2*pi*F*t);
S = reshape(s,4,[]);
Y1 = sum(S(1,:)-S(3,:));
Y2 = sum(S(2,:)-S(4,:));
Y = sqrt(Y1^2+Y2^2);
TT = max(t)/4*df;
Porog = 2*TT*2*A;
As a result, Y will be equal to 4 in this case. I want to plot Y versus n. And in principle any other. Just assigning for n = 2 ^ 3: 2 ^ 4: 2 ^ 5 doesn't work. How to get, depending on n, a set of all variables, including Y in the form of a row vector. And build a graph. Did not understand. Help me please. That is, (Y = 500, n = 5), (Y = 800, n = 10).

回答 (1 件)

Mathieu NOE
Mathieu NOE 2021 年 10 月 13 日
hello
maybe this ? (tested OK on my side)
clc
clearvars
A = 1;
df = 100000;
F = df/4;
% n = 2^3;
n = 2 ^ 3: 2^ 4 : 2 ^ 5;
for ci = 1:numel(n)
t = [0:n(ci)-1]/df;
s = A*sin(2*pi*F*t);
S = reshape(s,4,[]);
Y1 = sum(S(1,:)-S(3,:));
Y2 = sum(S(2,:)-S(4,:));
Y(ci) = sqrt(Y1^2+Y2^2);
TT(ci) = max(t)/4*df;
Porog(ci) = 2*TT(ci)*2*A;
end
plot(n,Y);
  2 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 10 月 25 日
hello again
problem solved ?
Mathieu NOE
Mathieu NOE 2021 年 11 月 5 日
hello
do you mind accepting my answer ?
tx

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

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by