Filter löschen
Filter löschen

problem with nested loop

1 Ansicht (letzte 30 Tage)
mak khatib
mak khatib am 19 Mai 2017
Bearbeitet: KSSV am 22 Mai 2017
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 Kommentar
Jan
Jan am 22 Mai 2017
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by