You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求编写Scilab的WeekDay()函数(支持select case与大小写兼容)

Scilab实现WeekDay()函数

函数代码

function num = WeekDay(dayStr)
    // 统一转换为小写,实现不区分大小写匹配
    lowerDay = lower(dayStr);
    
    select lowerDay
        case "周一" then
            num = 1;
        case "周二" then
            num = 2;
        case "周三" then
            num = 3;
        case "周四" then
            num = 4;
        case "周五" then
            num = 5;
        case "周六" then
            num = 6;
        case "周日" then
            num = 7;
        else
            error("输入无效,请输入周一至周日的字符串");
    end
    
    disp(num);
endfunction

功能演示控制台输出

测试不同格式的输入:

// 测试常规输入
WeekDay("周一")
// 输出: 1

// 测试大写输入
WeekDay("周日")
// 输出: 7

// 测试混合大小写输入
WeekDay("周三")
// 输出: 3

// 测试无效输入
WeekDay("星期八")
// 输出: !--error 999
// 输入无效,请输入周一至周日的字符串

内容的提问来源于stack exchange,提问作者Priyanka Gosai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 05:57:33