Using fprintf to printing non-vowels in command window

1 visualización (últimos 30 días)
Trying to adjust a previous program to print in the command window all the non-vowels from a inputted text file how do i fprint the code i have to show in the command window all the individual letters that arent vowles.
If text is "I love golf" command window should display like: lv glf
clear all
clc
inputfile = fileread('SampleText.txt');
Number_of_nonvowels = vowellesscounts(inputfile) % original
function w = vowellesscounts(s)
w=0;
l=length(s);
for i=1:l
if s(i)=='b' || s(i)=='c' || s(i)=='d' || s(i)=='f' || s(i)=='g' || s(i)=='h' || s(i)=='j' || s(i)=='k' || s(i)=='l' || s(i)=='m' || s(i)=='n' || s(i)=='p' || s(i)=='q' || s(i)=='r' || s(i)=='s'|| s(i)=='t' || s(i)=='v' || s(i)=='w' || s(i)=='x' || s(i)=='y'|| s(i)=='z'
w=w+1;
else
continue
end
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Sept. de 2021
function v = vowellesscounts(s)
v = '';
w=0;
l=length(s);
for i=1:l
if s(i)=='b' || s(i)=='c' || s(i)=='d' || s(i)=='f' || s(i)=='g' || s(i)=='h' || s(i)=='j' || s(i)=='k' || s(i)=='l' || s(i)=='m' || s(i)=='n' || s(i)=='p' || s(i)=='q' || s(i)=='r' || s(i)=='s'|| s(i)=='t' || s(i)=='v' || s(i)=='w' || s(i)=='x' || s(i)=='y'|| s(i)=='z'
w=w+1;
v(w) = s(i);
else
continue
end
end
end
  8 comentarios
Walter Roberson
Walter Roberson el 5 de Sept. de 2021
Editada: Walter Roberson el 5 de Sept. de 2021
inputfile = 'I love golf';
Number_of_nonvowels = vowellesscounts(inputfile); % original
fprintf('Edit this to say whatever you want: %s\n', Number_of_nonvowels);
Edit this to say whatever you want: lvglf
function v = vowellesscounts(s)
v = '';
w=0;
l=length(s);
for i=1:l
if s(i)=='b' || s(i)=='c' || s(i)=='d' || s(i)=='f' || s(i)=='g' || s(i)=='h' || s(i)=='j' || s(i)=='k' || s(i)=='l' || s(i)=='m' || s(i)=='n' || s(i)=='p' || s(i)=='q' || s(i)=='r' || s(i)=='s'|| s(i)=='t' || s(i)=='v' || s(i)=='w' || s(i)=='x' || s(i)=='y'|| s(i)=='z'
w=w+1;
v(w) = s(i);
else
continue
end
end
end
Joe Ainsworth
Joe Ainsworth el 5 de Sept. de 2021
thanks alot, i was missing the 'number_of_nonvowel'
very much appreciated @Walter Roberson

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by