Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

I have a problem when using the matlab. please help me.

1 visualizzazione (ultimi 30 giorni)
Min Gyu Lee
Min Gyu Lee il 24 Dic 2017
Chiuso: MATLAB Answer Bot il 20 Ago 2021
hello~!!
I have a problem when I use matlab. I want to skip the line that have specific characters.
examples : aaaaaaaaaaa.txt
dafdasdfasdfsdfa
****ddddddddddd
1.2.2.23.4.5.
3.3.45.t.
.g.g.f.g.h.
* dfdfd
**xddddddddddddd
I want to read the text without * rows.
please help me.

Risposte (1)

Harish Ramachandran
Harish Ramachandran il 28 Dic 2017
For a trivial implementation,
You can open the file, scan each line for the character " * " (using 'contains' function) and proceed to display the lines with no " * "
file = fopen('aaaaaaaaaaa.txt');
line = fgetl(file);
while ischar(line)
if contains(line,'*') == 0
disp(line)
end
line = fgetl(file);
end
fclose(file);
Based on the input you provided, the output of the code will be:
dafdasdfasdfsdfa
1.2.2.23.4.5.
3.3.45.t.
.g.g.f.g.h.
A more robust implementation would be to use textscan function.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!