Effacer les filtres
Effacer les filtres

Using fprintf to printing non-vowels in command window

1 vue (au cours des 30 derniers jours)
Joe Ainsworth
Joe Ainsworth le 5 Sep 2021
Commenté : Joe Ainsworth le 5 Sep 2021
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

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Sep 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 commentaires
Walter Roberson
Walter Roberson le 5 Sep 2021
Modifié(e) : Walter Roberson le 5 Sep 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 le 5 Sep 2021
thanks alot, i was missing the 'number_of_nonvowel'
very much appreciated @Walter Roberson

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by