Azzera filtri
Azzera filtri

Using fprintf to printing non-vowels in command window

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 5 Set 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 Commenti
Walter Roberson
Walter Roberson il 5 Set 2021
Modificato: Walter Roberson il 5 Set 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 il 5 Set 2021
thanks alot, i was missing the 'number_of_nonvowel'
very much appreciated @Walter Roberson

Accedi per commentare.

Più risposte (0)

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by