## how to find values from text file

Asked by Lalit Patil

### Lalit Patil (view profile)

on 19 Nov 2012
Accepted Answer by Pedro Villena

### Pedro Villena (view profile)

http://www.fileconvoy.com/dfl.php?id=geb61da744e17a7e317160537eeb2790920d297

```I = imread('Image.jpg');
i = I(:,:,3);
m = max(max(i));
[r c] = find(i ==m );
fid = fopen('lalit.txt','wt');
for j=1:length(r)
fprintf(fid,'%f %f\n',r(j),c(j));
end
fclose(fid);
```

in this text file min(r) = 1 and max(r) = 554..

for each r there is more than one value..

like, for each r =222, there is c = 231,419,421,422,424,425,426,427,428,429,430,431,432,433,434,438 so i want Z = round((max(c) + min(c))/2); = round((231 + 438)) = 335

and i want this for all r...

and then want to plot that values plot(z,r)

So, how to do this..?

## Products

### Pedro Villena (view profile)

Answer by Pedro Villena

### Pedro Villena (view profile)

on 19 Nov 2012
Edited by Pedro Villena

### Pedro Villena (view profile)

on 21 Nov 2012
```data = textread('lalit.txt');
r = unique(data);
for i=r',
c = data(data(:,1)==i,2);
z(i,1) = mean([min(c) max(c)]);
end
plot(r,z)
```

Lalit Patil

### Lalit Patil (view profile)

on 21 Nov 2012

I think this is the best solution you have given.. And this will solve many one's problems when they will search about this topic.. And the solutions you have given is not found anywhere.. Thank you tahnk you very much...

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.