error message for wrong data loaded

Hi everybody,
In my GUI I´m loading data and storing them into variables X and y. The a value is entered by user.It looks like that:
[FILENAME,PATHNAME]=uigetfile('*.txt')
loaddata=load(FILENAME)
if (a==1)
X = loaddata(:,1)
y = loaddata(:,2)
end
if (a==2)
X = loaddata(:,1:2)
y = loaddata(:,3)
end
...
But I would like to add an error message in case that user load the wrong data set if he set the value a is equal for example to 1. Do you guys have any idea ? TY for help

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 5 月 14 日

0 投票

See error() and warning() and warndlg() and disp() and fprintf()

7 件のコメント

Lenka Misenkova
Lenka Misenkova 2013 年 5 月 15 日
編集済み: Lenka Misenkova 2013 年 5 月 15 日
Thank you for your answer but I already know how to display error message. What I need is to make an condition something like: if (something is wrong) errordlg('Wrong data loaded'); end. So I ´m missing the if part.
Valmir Sadiku
Valmir Sadiku 2013 年 5 月 15 日
whence comes the 'a'? Is it user input data? You have to put more effort to get an answer.
Valmir Sadiku
Valmir Sadiku 2013 年 5 月 15 日
Sorry, my mistake.
If 'a' is an input data then you can simply do it in this way:
if( a == 1)
% load data set 1
elseif (a == 2)
% load data set 2
elseif (a == x)
% load data set x
else % wrong input from the user
% print error message
end
regards V.Sadiku
Lenka Misenkova
Lenka Misenkova 2013 年 5 月 15 日
uhm, but the user set value a(to be equal to 2) that means that his data are supposed to have 2 dependendent variable and one independent variable. It means his data have 3 columns. So imagine that he sat that he have 2 independent variables but he mistankely load data which have for example 4 or 5 columns. That´s the problem. I m sorry that I wasn´t descirbe exactly my problem earlier, but my english isn ´t also that good :D
Walter Roberson
Walter Roberson 2013 年 5 月 19 日
if ndim(loaddata) ~= 2 | size(loaddata,2) ~= 3
Lenka Misenkova
Lenka Misenkova 2013 年 5 月 20 日
Thank you ver much that works
Walter Roberson
Walter Roberson 2013 年 5 月 20 日
If your difficulty is solved, please mark this Answer as Accepted.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2013 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by