MATLAB Answers

Help!!! Why is it prompted that the subscript indices must be positive integer or logical type?

조회 수: 3(최근 30일)
Qiandong Dong
Qiandong Dong 2021년 2월 7일
댓글: Qiandong Dong 2021년 3월 1일
clear;clc;close all;
for e=1:0.2:2
n=(e-0.8)/0.2;
h(n)=n;
end
h
Why is it prompted that the subscript indices must be positive integer or logical type?
为什么提示下标索引必须为正整数类型或逻辑类型?

채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2021년 2월 11일
The value of n is a double whereas array indixes must be positive integers or logical type. Change the class of n to integer before indexing into h
for e=1:0.2:2
n = (e-0.8) /0.2;
class(n)
h(int32(n))=n;
end

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!