please give correction in code

The image and code is
clear all;
clc;
I = imread('l.jpg');
%RGB = RGB(:,:,3);
%GRAY = rgb2gray(I);
threshold = graythresh(I);
originalImage = im2bw(I, threshold);
i = bwareaopen(originalImage,350);
imshow(i)
m = max(max(i));
[r c] = find(i == m);
fid = fopen('lalit1.txt','wt');
for j=1:length(r)
fprintf(fid,'%f %f\n',r(j),c(j));
end
fclose(fid);
data = textread('lalit1.txt');
r = unique(data);
for i=r',
c = data(data(:,1)==i,2);
z(i,1) = mean([min(c) max(c)]);
end
This shows error..
??? Subscripted assignment dimension mismatch.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 11월 29일
편집: Andrei Bobrov 2012년 11월 29일

0 개 추천

last 6 rows:
r = unique(data);
z = nan(numel(r),2);
for i1 = 1:numel(r)
c = data(data(:,1)==r(i1),2);
z(i1,:) = mean([min(c) max(c)]);
end

댓글 수: 4

Lalit Patil
Lalit Patil 2012년 11월 29일
Again it shows error
??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Andrei Bobrov
Andrei Bobrov 2012년 11월 29일
corrected
Lalit Patil
Lalit Patil 2012년 11월 29일
Yeh, now it is working, but all values of Z are Nan.. Why.?
Walter Roberson
Walter Roberson 2012년 11월 29일
That would happen if r was empty.
textread() is obsolete. Please recode using textscan().
Walter Roberson
Walter Roberson 2012년 11월 29일

0 개 추천

Where does it show that error?
If it is the z assignment in the for loop, then put a breakpoint in at the assignment and show us size(c), and size(mean([min(c) max(c)]))

댓글 수: 3

Lalit Patil
Lalit Patil 2012년 11월 29일
No, it is not z assignment.. first column have some data, and for same no. in first column it will find all data related with that no. and it will do mean of max and min found from all data and it will assigned to z..
Walter Roberson
Walter Roberson 2012년 11월 29일
Which line is it producing the error message against?
problem get solved..
I have changed only
c = data(data(:,2)==i,1);
Thank you...!

이 질문은 마감되었습니다.

질문:

2012년 11월 29일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by