Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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".
 
  • Like
Reactions: blooz

    blooz

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top