ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ
ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ

Index in position 1 exceeds array bounds (must not exceed 1). How do I fix this error?

์กฐํšŒ ์ˆ˜: 1 (์ตœ๊ทผ 30์ผ)
Elizabeth Antohi
Elizabeth Antohi 2020๋…„ 7์›” 19์ผ
ํŽธ์ง‘: Elizabeth Antohi 2020๋…„ 7์›” 19์ผ
n = input('Number of dice: '); %number of dice being rolled
numberOfExperiments = input('Number of trials: ');
faces = input('Number of faces: ');
a = {'G1' 'g1'}
b = {'G2' 'g2'}
X = randn(numberOfExperiments, 2)
for rows = 1:numberOfExperiments
i =randperm(length(a),1)
A=a(i)
B=b(i)
Anew = cell2mat(A)
Bnew = cell2mat(B)
for cols = 1:2
C(:,cols) = X(Anew, Bnew)
end
C(rows, :) = X(Anew, Bnew)
end
  ๋Œ“๊ธ€ ์ˆ˜: 1
Image Analyst
Image Analyst 2020๋…„ 7์›” 19์ผ
What is the purpose of a and b? And what is faces used for? You never use it. Put in some comments to explain it to us. Often if you put in comments, you'll realize the error on your own.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

SAA
SAA 2020๋…„ 7์›” 19์ผ
Anew and Bnew are not integers, you define a and b as cells with chars then use cell2mat but they are still not integers so you'll get an error. You can't use chars for indexing.
Also just like Image Analyst suggested, comments would help help both you and the person that's tryin to help ๐Ÿ˜ƒ๐Ÿ˜„

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Genomics and Next Generation Sequencing์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

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

Start Hunting!

Translated by