I am trying to plot the each value of C at different theta values, but I found an error. Error: Invalid expression. When calling a function or indexing a variable, use parenth

1 回表示 (過去 30 日間)
clear all
clc
c=[0.5,0.75,1,1.1];
theta=[-pi:0.01:pi];
a=zeros(1,629);
for k=c
G(k)=(1+4*(a(k)).^2-a(k)).*(sin(theta/2)).^2);
plot(G(k),theta);
end
  3 件のコメント
Seifeldin Mohamed
Seifeldin Mohamed 2022 年 12 月 5 日
Cs are required values!! , so which statment should be edite to be able to count for float numbes !!
Walter Roberson
Walter Roberson 2022 年 12 月 5 日
Are you trying to define G as being a piecewise formula? Or is G to be a matrix of values? Matrices need to be indexed with positive integers.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2022 年 12 月 5 日
you have too many ) on that line.

Alan Stevens
Alan Stevens 2022 年 12 月 5 日
Do you want something more along the following lines?
c=[0.5,0.75,1,1.1];
theta=-pi:0.01:pi;
%a=zeros(1,629);
for k=1:numel(c) % numel is number of elements in c
% There are four values of c and all the a's are zero
% so I've replaced a by c in the following.
G(k,:)=(1+4*c(k).^2-c(k)).*sin(theta/2).^2;
end
plot(theta,G);
xlabel('\theta'), ylabel('G')

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by