I keep getting this error.....
Index in position 1 exceeds array bounds (must not exceed 1).
Error in IHC_Continous_Quantification (line 28)
xlswrite('Staining.xlsx', percentage, 'B2:B3');
....from this code...
%Initialize
clc
addpath('/Users/benjaminreeves/Desktop/Test');
for i = 1:2
path = dir(strcat('/Users/benjaminreeves/Desktop/Test'));
filename = strcat(['im', num2str(i),'.tiff']);
images = imread(filename);
img = rgb2gray(images);
level = 0.60;
imbw = imbinarize(img, level);
imwrite(imbw, strcat('/Users/benjaminreeves/Desktop/Test/bwim/imbw', num2str(i), '.tiff'));
imtool(imbw);
total_pixels = numel(imbw);
total_white = nnz(imbw);
total_black = (total_pixels - total_white);
percentage = ((total_black/total_pixels)*100);
xlswrite('Staining.xlsx', percentage, 'B2:B3');
sprintf('The pecentage of imaged tissue, im%1.0f, that is stained is %.3f', i, percentage)
end
....I am brand new to coding and just trying to learn! No background at all.

댓글 수: 3

Bob Thompson
Bob Thompson 2018년 12월 5일
I would suggest moving the xlswrite command outside of your loop, and print the entire percentage array at one time. You can capture all of the percentage values into one array by replacing 'percentage' with 'percentage(i)'.
Benjamin Reeves
Benjamin Reeves 2018년 12월 5일
seems to be a fundamental error. i just opened a new sheet and tried to do
A = [1, 1]
xlswrite(filename, A)
and i got the same error about "exceeding number of array elements..
Bob Thompson
Bob Thompson 2018년 12월 5일
편집: Bob Thompson 2018년 12월 5일
Is 'filename' being opened correctly? Can you use xlsread, or fopen on 'filename' and get something useful out of it?
What exactly do you mean by 'opened a new sheet'? Did you make a new sheet in the excel file? If so, you need to specify that is the sheet you want to use.
Do you have the file open already? I don't think this should cause too much of a problem, but it's possible.
Is 'percentage' actually an array of doubles? I assume it is, but I haven't specifically run your code, so I can't check these things myself.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Remington
Steven Remington 2018년 12월 10일

0 개 추천

You may have accidentally created a variable called 'xlswrite' and thus it thinks you are trying to reference the variable, not the function. Try running the following command then rerun your code:
>> clear xlswrite

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

질문:

2018년 12월 5일

답변:

2018년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by