print()错误:“输出参数"varargout" (可能还有其他)(未分配) [英] Error with print(): "Output argument "varargout" (and maybe others) not assigned"
问题描述
我一直试图在MATLAB中编写一个简单的脚本来绘制图像,询问用户是否要将其打印到文件中,然后(如果是)执行此操作.但是,我在print()
函数中遇到了一个奇怪的错误.这是我的代码:
I have been trying to write a simple script in MATLAB that plots an image, asks to user if they want to print it to a file, and (if yes) does this. However, I have met a strange error with the print()
function. Here is my code:
plot(X, Y, 'red');
choice = input('Do you want to print to file this 2D image ? [y/n] ', 'y');
if(choice=='Y' || choice=='y')
{
print(hFig, '-dpng', strcat(filename, '.png'));
}
如果正在运行,它将停止在if
语句内,并显示错误:
If running, it stops inside the if
statement with the error:
==>中的错误打印为161 err.message ='';
Error in ==> print at 161 err.message='';
???在输出过程中未分配输出参数"varargout"(可能还有其他参数) 调用"C:\ Programmi \ MATLAB \ R2010a \ toolbox \ matlab \ graphics \ print.m>打印".
??? Output argument "varargout" (and maybe others) not assigned during call to "C:\Programmi\MATLAB\R2010a\toolbox\matlab\graphics\print.m>print".
在30次打印时==>直方图错误(hFig,'-dpng',strcat(filename,'.png'));
Error in ==> istogramma at 30 print(hFig, '-dpng', strcat(filename, '.png'));
为什么会出现此错误,如何避免这种情况?
Why am I getting this error and how can I avoid this?
推荐答案
您的带有{
和}
的if
代码似乎很奇怪,在MATLAB中{
和}
用于单元格数组和单元格数组索引,不用于代码结构化.此外,input
的第二个参数必须为's'
,而不是像您一样的'y'
.
Your if
code with {
and }
seems strange, in MATLAB {
and }
are used for cell arrays and cell array indexing, not for code structuring. Further, the second argument for input
must be 's'
, not 'y'
as you have.
固定代码:
choice = input('Do you want to print to file this 2D image ? [y/n] ', 's');
if(choice=='Y' || choice=='y')
print(hFig, '-dpng', strcat(filename, '.png'));
end
编辑:继续询问直到用户用"y","Y","n"或"N"回复:
to keep asking until user responds with 'y', 'Y', 'n' or 'N':
choice = '';
while ~ismember(choice, {'y', 'Y', 'n', 'N'})
choice = input('Do you want to print to file this 2D image ? [y/n] ', 's');
end
if(choice=='Y' || choice=='y')
print(hFig, '-dpng', strcat(filename, '.png'));
end
这篇关于print()错误:“输出参数"varargout" (可能还有其他)(未分配)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!