필터 지우기
필터 지우기

problem with nested loop

조회 수: 1 (최근 30일)
mak khatib
mak khatib 2017년 5월 19일
편집: KSSV 2017년 5월 22일
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
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개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by