Input Dialog error :(

조회 수: 7 (최근 30일)
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 13일
댓글: Edmund Paul Malinowski 2015년 11월 13일
Hi all :)
I'm trying to get user input for note values so i eventually can play any note in an octave. Although yesterday it was working fine, for some reason my code to take user input keeps erroring with:
Attempt to execute SCRIPT dialog as a function:
C:\Users\Paul\Documents\MATLAB\dialog.m
Error in inputdlg (line 123)
InputFig=dialog( ...
Error in dialog (line 8)
answer=inputdlg(prompt,name,[1 50],defaultans);
Here's my code for it and although i'm new to matlab, i cannot for the life of me see any differences or errors in the code from what i found on this site:
% SHOW INPUT DIALOG AND TAKE USER INPUT..
prompt={'1st Note','2nd Note','3rd Note','4th Note','5th Note','6th Note','7th Note'};
name='Enter Note Values (C, D, etc)..';
num_lines=1;
defaultans={'C','D','E','F','G','A','B'};
answer=inputdlg(prompt,name,[1 50],defaultans);
% CONFIGURE INPUT TO VARIABLES..
Note1 = answer{1};
Note2 = answer{2};
Note3 = answer{3};
Note4 = answer{4};
Note5 = answer{5};
Note6 = answer{6};
Note7 = answer{7};
Any ideas why its erroring out on me? Yesterday with the same code, it displayed the dialog box but today, the error :(
Thanks,
Paul
  댓글 수: 1
Adam
Adam 2015년 11월 13일
How are you calling that? The error message suggests you are trying to call it using function syntax. Although it also says the error is on line 8 of the file that is supposedly being called with the wrong syntax so I'm not sure at a glance.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2015년 11월 13일
You created your own script file named dialog.m, located in the directory C:\Users\Paul\Documents\MATLAB. When the inputdlg function included in MATLAB attempts to call the dialog function included in MATLAB your script named dialog takes precedence (because "C:\Users\Paul\Documents\MATLAB" is your current directory, I assume?) and so inputdlg attempts to call your script as a function. That's why you receive an error.
The solution is for you to rename your dialog.m script file.
  댓글 수: 2
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 13일
Hey Steven, thanks for your response. Oh i see now, so what would i need to rename my .m file to? This is for an assignment for my degree so i think i need to have the script file saved somewhere like i have. Is it just that the file is not in the main matlab folder / directory?
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 13일
Ah sorry, i just renamed it and bingo. I'm guessing that the name 'dialog' itself was the issue. Thank you so much :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 13일
Hey Adam,
Although my main code has so much more in it, this is a tiny snippet i copied into a new .m file to test so i'm only calling it as it is there. No additional code or file calls it.
In my main code file, it was working yesterday, as in it displayed the dialog box etc but running it today its not working. I haven't changed anything except for adding the bit converting the answer array into individual variables but it doesn't even get that far. I'm totally stumped..

Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 13일
Also, in the command line error:
Error in inputdlg (line 123)
InputFig=dialog( ...
I don't have 123 lines in my code.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by