0

i am trying to fetch integer value stored in result_cluster.txt and trying to store into an array

aiclu(i,1)=a; 

but I'm not getting the desired result. Instead a value of 0 is stored in the array. Here's my code:

fid20=fopen('result_cluster.txt','r');
i=1;
k=1;
aclu_end=zeros(11,1);
aiclu=zeros(962,1);

while(~feof(fid20))

   a=fscanf(fid20,'%d',1);
   disp(a); 
   disp(i);

   aiclu(i,1)=a; 
   i=i+1;

   disp(aiclu(i,1));
   if a==32
     aclu_end(k,1)=i;

     disp('hello');
     disp(aclu_end(k,1));
     k=k+1;
   end    
end
fclose(fid20);

result_cluster.txt

2
3
4
34
56

81
85 
89

102
109
110 
...

I get this output:

disp(a) = 2
disp(i) = 1

For aiclu(i,1)=a; I get this error: "??? Subscripted assignment dimension mismatch."

1
  • Are you sure that a is a single value and not a vector? a being a vector would cause that error. Commented May 15, 2013 at 20:14

1 Answer 1

2

Your issue is in line 14 of your code above. You increment i - and then display it. So while you store the value of a in aiclu(i,1), you are actually displaying aiclu(i+1,1).
Your code runs fine when I try it and your error doesn't occur until the end of the file - so the condition for your while-loop is inadequate.

Edit

If you run your code in the Matlab debugger, you'll notice that the last value for a is an empty vector:

a = []  

This cannot be assigned to aiclu.

Sign up to request clarification or add additional context in comments.

1 Comment

@tabish : Please consider accepting this answer by clicking the checkmark (✓) next to the voting buttons or comment on what doesn't work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.