How to be able to control reading text in matlab

Hi. I've updated my codes. In the "CONTROL READING SECTION" focusing on the if statement, The response I want to see is that, when every time I type 1 i proceed to the next letter. In this case I read A already. How am I gonna proceed to letter B, and how am I gonna proceed to C when I'm already in B?
%------------TXT FILE-----------%
% text file contains "ABC" inside.
% text file's "ABC" have been converted in to ascii
% A = '1' '0' '0' '0' '0' '0' '1'
% B = '1' '0' '0' '0' '0' '1' '0'
% C = '1' '0' '0' '0' '0' '1' '1'
clc;
fid = fopen('letterabc.txt', 'r');
Data = fread(fid);
CharData = char(Data);
ascii = dec2bin(CharData);
Text = [ascii, CharData];
out = num2cell(ascii);
%-----------------CONTROL READING-------%
prompt = 'type 1 for next';
x = input (prompt);
if x == 1
disp(out(1:1,:)) % after this, if I type 1 I want to be able to read B which is
%'1' '0' '0' '0' '0' '1' '0'
% The response that I want is, everytime I type 1, I can read the next letter
% A to B to C.
% how to be able to do this code?
else
fclose(fid);
return;
end
THE OUTPUT OF THIS CODES LOOKS LIKE THIS:
type 1 for next 1
'1' '0' '0' '0' '0' '0' '1'

4 comentarios

Your question is not clear...are you expecting this?
str = '1000001' ;
result= (str-'0')
Guillaume
Guillaume el 1 de Ag. de 2017
Not only is the question extremely unclear, but so is the code. In particular, the second part, from out = .... is completely independent of the contents of the file.
Jan
Jan el 2 de Ag. de 2017
The question is still not clear. What do you want to achieve? Please do not post code as screenshot, because then the readers have to type it again for experiments. Post it as text instead.
I updated my question already. Can you please look at it again? Thank you very much for your guidance

Respuestas (1)

ES
ES el 2 de Ag. de 2017
fid = fopen('letterabc.txt');
tline = fgetl(fid);
while ischar(tline)
YesOrNo = input('continue Reading [y/n]')
if strcmpi(YesOrNo, 'y')
disp(tline)
tline = fgetl(fid);
else
fclose(fid);
return;
end
end
fclose(fid);

La pregunta está cerrada.

Preguntada:

el 31 de Jul. de 2017

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by