Using fprintf to printing non-vowels in command window

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
Walter Roberson
Walter Roberson am 5 Sep. 2021
Bearbeitet: Walter Roberson am 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 am 5 Sep. 2021
thanks alot, i was missing the 'number_of_nonvowel'
very much appreciated @Walter Roberson

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by