Info

この質問は閉じられています。 編集または回答するには再度開いてください。

please give correction in code

1 回表示 (過去 30 日間)
Lalit Patil
Lalit Patil 2012 年 11 月 29 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 日
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 日
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 日
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 件のコメント
Walter Roberson
Walter Roberson 2012 年 11 月 29 日
Which line is it producing the error message against?
Lalit Patil
Lalit Patil 2012 年 11 月 29 日
problem get solved..
I have changed only
c = data(data(:,2)==i,1);
Thank you...!

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by