How to convert to cell

% load data_latih dan target_latih hasil pelatihan
load data_latih
load data_target
% pengujian menggunakan algoritma multisvm
output = multisvm(data_latih,data_target_latih,data_uji);
disp(output);
switch output
case 1
gambar_wajah = 'Candra';
case 2
gambar_wajah = 'Danu';
case 3
gambar_wajah = 'Darma';
case 4
gambar_wajah = 'Fajar';
case 5
gambar_wajah = 'Fakri';
case 6
gambar_wajah = 'Fauzan';
case 7
gambar_wajah = 'Fuadi';
case 8
gambar_wajah = 'Gunadi';
case 9
gambar_wajah = 'Gunawan';
case 10
gambar_wajah = 'Khairul';
otherwise
gambar_wajah = 'tidak dikenali';
end
% menampilkan hasil identifikasi jenis bunga pada edit text
set(handles.edit1,'String',gambar_wajah)
I have error
SWITCH expression must be a scalar or character vector constant.
Error in main_program>pushbutton_Identifikasi_Callback (line 191)
switch output
the result off >> output = multisvm(data_latih,data_target_latih,data_uji);
is
1
1
1
1
1
1
1
1
1
1
1
1
6
6
how to covert that result to matrik
example
A=[1 1 1 1 1 1 1 1 1 1 1 1 6 6]
then i can count how many same number in that matrik
example 1
the if number 1 have more the 5
return
case 1
gambar_wajah = 'Candra';
the if number 2 have more the 5
case 2
gambar_wajah = 'Danu';
the if number 2 have more the 5
case 3
gambar_wajah = 'Gunawan';
otherwise
gambar_wajah = 'tidak dikenali';

1 Comment

You can use the following way to change this column vector into a cell
output_cell = num2cell(output);
However, you will still get the same error.
The error you got here is because output is an column vector but switch can only takes a scalar (1x1 matrix) or character vector constant (string).
you may want to create a for loop to handle the each element in output by using switch output(i) assuming the i is the loop variable.
You can use the following way to count how many same number in the vector
num_of_1 = sum(output == 1);
this will get how many 1s in the output matrix.
Hope this can help you.

Sign in to comment.

Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

on 16 Dec 2020

Commented:

on 26 Oct 2022

Community Treasure Hunt

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

Start Hunting!