Index out of bounds
이전 댓글 표시
I am trying to use the patient number inputed into the filename to access the correct body information. There are 4 patients and each has 8 related properties. When I define which patient number it is from the filename, it brings up the correct number, and when I use that number manually to define the index in tbw the code works fine. But when I use the variable name, it somehow uses a different value for 'patientno' (its actually adding 48 to the value. e.g. patient 2 tries to index 50)
Here is my code:
patientno = filename(2);
patientstats = zeros(4,8);
patientstats(1:4,1:8) = [860.0,75.7,39.1,9.2,174.0,43.3,38.1,30.0; 702.0,62.2,36.5,9.9,165.0,39.3,40.0,29.0; 800.0,98.4,43.0,7.2,170.0,47.5,40.9,26.0; 980.0,80.2,53.9,12.3,175.0,41.0,41.0,27.5];
%Define individual anthropometric information
tbw = patientstats(patientno,1)
tw = patientstats(patientno,2);
채택된 답변
추가 답변 (1개)
Joseph Cheng
2015년 3월 3일
1 개 추천
From what i see filename is probably a string, so what you're doing is trying to access patientstats('2',1) and patientstats('2',2), which '2' is an ascii character which has the decimal equivalent of 50. you'll need to use str2num(patientno) to convert it to decimal.
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!