[SOLVED] Matlab error in file handling

Status
Not open for further replies.

blooz

Advanced Member level 2
Joined
Dec 29, 2010
Messages
560
Helped
121
Reputation
242
Reaction score
116
Trophy points
1,343
Location
India
Activity points
4,985
Code:
for i=1:2048
    temp=dec2hex(i,3);
    size(temp)
    if(strcmp(temp,addr))
        mem(i)=data;
    else 
        mem(i)='000';
    end 
end
a String data is read in to addr and data and both of length 3......
but it's not working

??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> f at 43
mem(i)='000';



error reported



The aim of the script was to read a file and produce an output file where addr is variable of range 000 to 7FF and similarly data could be a random value of range 000 to FFF,

the approach was

for i=1 to 2048

if(i==addr)
mem(addr)=data;
else
mem(addr)=000;


mem(addr)=
 

the dec2hex function returns a vector of characters (1x3, in your case). You need to define mem as a 2048x3 array and make the assignment as:
Code:
mem(i,:)=data;
where the ":" means "all the columns of mem".
 
Reactions: blooz

    blooz

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…