how to convert an array to corresponding weekdays

If I have an array z = [ 1 2 3 4 5 6 7], how can I convert it to corresponding weekdays like p = [ monday tuesday wednesday thursday friday saturday sunday]?

 采纳的回答

I am not certain what you want.
Try this:
z = [ 1 2 3 4 5 6 7];
p = { 'monday' 'tuesday' 'wednesday' 'thursday' 'friday' 'saturday' 'sunday' };
chooseDay = 4;
Out = p(z == chooseDay)
producing:
Out =
1×1 cell array
{'thursday'}
.

4 个评论

Thank you for you response and I am really sorry that I didn't make I intentions clear. I looking ways or functions that will convert these number to days automatically like the weekdays functionb. It gives the name of the day but onl;y if assigned to have a second output:
[daysnumber, daysname] = weekdays()
is there any other function I can use to convert the numbers to days without needing the second output. I am not sure if I have made myself clear this time too. But thank you for your response
The only way I can think of to do that is to write your own ‘helper’ function:
function name = daysname(x)
[~,name] = weekday(x);
end
so:
name = daysname(now)
produces:
name =
'Mon'
.
nice solution. Thanks a ton mate!! :D
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by