Attempt to reference field of non-structure array.

Hi, I'm trying to run the below code and its giving error as 'Attempt to reference field of non-structure array'.
code:
clc
close all
clear all
x=2;
D=[1 0 1 0];
X=[1;x;x.^2;x.^3];
dx=D.X;
gx=1+x+x.^3;
Could you please help to rectify this error?

回答 (2 件)

KSSV
KSSV 2018 年 3 月 6 日
編集済み: KSSV 2018 年 3 月 6 日

0 投票

See this line
dx=D.X;
This should be element by element multiplication I guess. * is missing in that line. When you use simply '.', it is expecting D to be a structure, which is not.
clc
close all
clear all
x=2;
D=[1 0 1 0];
X=[1;x;x.^2;x.^3];
dx=D.*X;
gx=1+x+x.^3;
Andrei Bobrov
Andrei Bobrov 2018 年 3 月 6 日

0 投票

Maybe this?
x=2;
D=[1 0 1 0];
X=[1;x;x.^2;x.^3];
dx=D*X;
gx=1+x+x.^3;

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

質問済み:

2018 年 3 月 6 日

回答済み:

2018 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by