For loop question, switch loop question, don't know how to incorporate them together
1 次查看(过去 30 天)
显示 更早的评论
function [ vowels ] = findVowels( charCell )
string st = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
a = st[Random.Range(st.Length)];
charCell = {a1, a2; a3, a4};
switch vowles(letter)
case {'a' 'e''i''o''u'}
a = {'letter1','letter2';'letter3','letter4'};
otherwise
disp a = []
end
My answer:
function [ doy ] = calcDayOfYear( day, month, year )
% Day, month and year are integers corresponding to a given date
%and day is that date's of the year
if doy = numDays*month
if year = 'a leap year';
if year./400 = 2n;
disp('a leap year');
elseif (year./100 = 2n;
disp('not a leap year');
elseif year./4 = 2n;
disp('a leap year');
else
disp('not a leap year');
end
numDays = 29;
else
numDays = 28;
end
switch lower(month)
case {1 3 5 7 8 10 12}
numDays = 31;
case {4 6 9 11}
numDays = 30;
case {2}
if year = [a leap year];
numDays = 29;
otherwise
numDays = 28;
end
Totally have no idea how to incorporate them together, it is such a mess for my code too
Thanks a lot for whoever is answering my question.
2 个评论
Rajesh Balagam
2017-10-16
Please rephrase your question specifying the location of the issue. Also explain the problem you are trying to solve and how you are approaching it.
Walter Roberson
2017-10-16
See https://www.mathworks.com/matlabcentral/answers/361259-for-loops-questions#answer_285751 for an analysis of the first part.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!