problem with nested loop
显示 更早的评论
actually i'm working on a code that reads a text (message) and another text (cover), and i have converted (message) to Binary and the process is to check (message); if message = 0 go to (cover) to the first word and take the first character and put it in an array else ( 1 ) take the last character and then go to the second bit in (message) and see the second word in (cover) and so on if the word has the same start and end, eliminate it. i have problems with nested for loops which has if statements inside, the code
%%Reading the secret message
fid = fopen('message.txt','r');
Data=fread(fid);
text=char(Data);
fclose(fid);
disp(text);
%converting the message to binary (BIN)
bin=dec2bin(Data);
disp(bin);
%Reading the cover paragraph
fid = fopen('cover.txt','r');
cover=fread(fid);
Char=char(cover);
fclose(fid);
%KEY for the message ( if 0 => start, if 1 => end )
n=0; %counter for the KEY entries
%Defining variables for rows and columns of the BIN and COVER for
%processing
row=size(bin,1);
col=size(bin,2);
A=zeros(24,1);
%Reading bit by bit from BIN to hide in the cover
new = textread('cover.txt', '%s', 'delimiter', ' ');
[r,c]=size(new);
for k=1:1:r
q= new{r,1};
n=num2cell(q);
[cr,cc]=size(n);
for u=1:1:cc
for i=1:1:row
for j=1:1:col
x=bin(i,j);
h = str2double(x);
y=bi2de(h);
if y==1
Z(i,j)=n(1,cc);
else
Z(i,j)=n(1,1);
end
end
end
end
end
Thank you
1 个评论
Jan
2017-5-22
The code is not readable. Are you interested in providing readable code? Then mark it and hit the "{} Code" button.
The current description of the problem is very vague:
i have problems with nested for loops which has if
statements inside
Please mention the corresponding lines and explain, which problems you have. It is much easier to suggest a solution when we do not have to guess the problem.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!