how to put two doubles coulmns and third is strings in uitable GUI?

3 views (last 30 days)
I am trying to get the results of my predication to be in two columns where zeros and ones while the third column give me the closest neighbours based on KNN using the Names
i tried the following:
resultdata= [Double' doubleout KNnames];
columnformat = {'numeric','numeric','char'};
set(handles.uitable2, 'Data',resultdata , 'ColumnFormat',columnformat);
but not working I want to be like the following knowing that I loaded the first columns from files and the third two from another excel file
Column1 cloumn2 column 3
1 1 y1
0 1 y3
  2 Comments
Andreas Donauer
Andreas Donauer on 28 Jun 2016
Edited: Andreas Donauer on 28 Jun 2016
Not working = you get an error message?
Also, could you clarify what the input data ("Double", "doubleout" "KNnames"). I'd guess you mixed something up trying create "resultdata" and your dimensions do not agree.
That said: "resultdata" is a cell array? (If it is not, try "{}" instead of "[]" for "resultdata")
essam
essam on 29 Jun 2016
Edited: Walter Roberson on 29 Jun 2016
thanks for reply here the code concerns that part
global KIn NIn knames;
try
k= eq(KIn,NIn) %test equaltiy of NN and KNN predication
d=logical(k); %conver zeros and ones to True and false
set(handles.uitable1, 'Data',{k,d,knames} , 'ColumnFormat',{'numeric','char','char'});
catch ME
message = sprintf('Error:\n%s', ME.message);
uiwait(warndlg(message));
end
where KIn is the predication results of KNN which will be in zeros and ones , while NIn is the predication results of NN also in zeros and ones, for Knames is the predication results of KNN where it containes the names of the nearest companies for example (Y1,2009 y2,2009) so On
I make equality to test if there is difference in predication and logical to give me in text true or false the predication and it works fine to put both together in uitable, but tried to add Knames with same string format gives me the following error
first if its []
Dimensions of matrices being concatenated are not consistent
second if I used {}
while setting the data property of <a hred = matlab.doc matlab ui conteol.table'> Table
Data within a cell array must have size [1 1]
hope I can solve that

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jun 2016
Edited: Walter Roberson on 29 Jun 2016
'Data', [num2cell(k(:)), num2cell(d(:)), knames(:)]
provided your knames is a cell array of strings.
  3 Comments
Walter Roberson
Walter Roberson on 29 Jun 2016
You had {k,d,knames} . That means to create a 1 x 3 cell array in which the first element is "everything in k", the second element is "everything in d" and the third element is "everything in knames". But that is not what you want: you want a (something by 3) cell array in which each element of the cell array has exactly 1 numeric value (first two columns) or exactly 1 string (third column). So you need to convert the numeric vectors into cell arrays with one numeric value per array element, which is exactly the purpose of num2cell. The (:) part ensures that you get a column vector of results. When you have the cell array made by converting k, and the cell array made by converting d, and the existing cell array of strings in knames, then you can put those together in a (something by 3) cell array by using the horzcat() operation, the short form of which is []

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!