Yahoo奇摩知識+將於 2021 年 5 月 4 日 (美國東部時間) 終止服務。自 2021 年 4 月 20 日 (美國東部時間) 起,Yahoo奇摩知識+服務將會轉為唯讀模式。其他Yahoo奇摩產品與服務或您的Yahoo奇摩帳號都不會受影響。如需關於Yahoo奇摩知識+ 停止服務以及下載您個人資料的資訊,請參閱說明網頁。
求MATLAB GUI一個程式功能隨便都行(20點)
如題,球一個用matlab寫的程式,功能隨便都行,加數字的也ok,邦我寫的人真是感激不盡阿。
4 個解答
- 老師Lv 72 0 年前最佳解答
隨便一個簡單的GUI檔案
若是使用GUIDE作的
一定超過2000字
2006-06-09 11:20:52 補充:
% 這個程式使用了 questdlg, inputdlg, msgbox 三種對話框% 計算三角形或矩形的面積% Date: 4/28/2006 w=1;while w==1 Button=questdlg('要計算矩形或三角形面積?','請選擇','矩形','三角形','三角形');% Create and display question dialog box% button = questdlg('qstring','title','str1','str2','default') % creates a question dialog box with two push buttons labeled % 'str1' and 'str2'. 'default' specifies the default button selection % and must be 'str1' or 'str2'.switch Button case '三角形' prompt={'請輸入三角形底的長度 (cm)','請輸入三角形的高度 (cm)'}; aa=inputdlg(prompt,'計算三角形面積',1); a=str2num(aa{1});b=str2num(aa{2}); % Create and display input dialog box% answer = inputdlg(prompt,dlg_title,num_lines) area=1/2*a*b; case '矩形' prompt={'請輸入矩形的長度 (cm):',';請輸入矩形的寬度 (cm):'}; fields={'length','width'}; a=inputdlg(prompt,'計算矩形面積',1);% b=inputdlg('請輸入矩形的寬度 (cm)','計算矩形面積',1); aa=cell2struct(a,fields); a=str2num(aa.length);b=str2num(aa.width); area=a*b; end[IConData,IConCMap]=imread('MathWorks.Logo.gif');title='Compute result';A='------------------------------------';str=sprintf(['The computed results is:\n',A, ... ' \n Area = %g (cm^2) \n',A],area);hm=msgbox(str,title,'custom',IConData,IConCMap);pause(5);% Create and display message box% msgbox(message,title,'icon') specifies % which icon to display in the message box. % 'icon' is 'none', 'error', 'help', 'warn', or 'custom'. % The default is 'none'.tryagain=questdlg('還要不要再做一次計算','請選擇','Yes','No','Yes'); if strcmp(tryagain,'Yes') w=1; else w=0; endendclose(gcf);------------------------------------存檔成為 cal_area.m 執行看看希望對你有幫助
2006-06-11 14:20:26 補充:
[IConData,IConCMap]=imread('MathWorks.Logo.gif');
一定是這裡錯誤
因為你沒有 MathWorks.Logo.gif檔案
參考資料: 我自己寫的 - 1 0 年前
請問老師,我適用7.0的跑你的程式
一開始會出現按"三角形"還是"矩形"的
但是按下去之後,不會出現輸入長與高的選項
以下是我用7.0跑出來的錯誤
Error in ==> guihandles>createHandles at 114
handles.(tag) = [prev_h this_h];
Error in ==> guihandles at 75
handles = createHandles(fig);
Error in ==> inputdlg at 305
handles = guihandles(InputFig);
- ?Lv 42 0 年前
這是我也的猜數字遊戲,使用內建的函數
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function gameNumber
answer = input('Set a number = (n-digits, n <= 10) ','s');
clc;
prompt={strvcat(['Enter the number what you guess (',num2str(length(answer)),'-digits) :'], ...
'if input = -1 end of the game...',...
'Rule : The number can''t repeat 0-9 digit.'),'The result is :'};
name='No. # 0';
numlines=1;
defaultanswer={'','0A0B'};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
guess = defaultanswer;
match = 0;
N = 1;
while (~strcmp(guess{2},'-1'))
guess = inputdlg(prompt,name,numlines,defaultanswer,options);
if ~isempty(guess) && length(guess{1}) ~= length(answer)
if match == 0
errordlg('The two numbers must be the same length !!');
end
break;
elseif isempty(guess) || match == 1
break;
end
[words, match] = compare_number(answer, guess{1});
defaultanswer{1} = guess{1};
defaultanswer{2} = words;
name = ['No. # ',num2str(N)];
N = N+1;
end
function [words, match] = compare_number(answer, guess)
match = 0;
ind = find(answer == guess);
if length(ind) == length(answer)
words = [num2str(length(ind)),'A0B (Bingo!!!)'];
match = 1;
return;
end
Aword = [num2str(length(ind)),'A'];
B = 0;
for k =1 : length(guess)
if isempty(find( ind == k ))
if ~isempty(find(answer == guess(k)))
B = B + 1;
end
end
end
Bword = [num2str(B),'B'];
words = [Aword, Bword];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> gameNumber
Set a number = (n-digits, n <= 10) 1234 %先設定答案一個數字
%接著會開啟GUI,進入猜數字的過程
2006-06-16 01:32:20 補充:
選擇三角形(不打字)-->Cancel會有error message
#####################
??? Index exceeds matrix dimensions.
Error in ==> guiTest at 18
a=str2num(aa{1});b=str2num(aa{2});
######################
參考資料: None