Error in following code while converting cell to matrix

2 ビュー (過去 30 日間)
Balaji M. Sontakke
Balaji M. Sontakke 2018 年 6 月 21 日
コメント済み: Balaji M. Sontakke 2018 年 6 月 22 日
Error in following code
Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects.
Error in Fusion_Minutie_InvMoment (line 18)
fusion = cell2mat(out);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V = {load('db1.mat'),load('db2.mat'),load('db3.mat'),load('db4.mat')};
n = cellfun(@fieldnames,V,'un',0);
V1 = cellfun(@(x,y)[x.(y)]',V,[n{:}],'un',0);
V2 = [V1{:}];
V3 = cell2mat(reshape(V2,1200,[]));
V4 = mat2cell(V3,4*ones(size(V3,1)/4,1),7);
out = mat2cell(V4,[400,800],1);
fusion = cell2mat(out);

回答 (2 件)

Majid Farzaneh
Majid Farzaneh 2018 年 6 月 21 日
Hi, you can do it like this:
V = {load('db1.mat'),load('db2.mat'),load('db3.mat'),load('db4.mat')};
n = cellfun(@fieldnames,V,'un',0);
V1 = cellfun(@(x,y)[x.(y)]',V,[n{:}],'un',0);
V2 = [V1{:}];
V3 = cell2mat(reshape(V2,1200,[]));
V4 = mat2cell(V3,4*ones(size(V3,1)/4,1),7);
out = mat2cell(V4,[400,800],1)
fusion1 = cell2mat(out{1});
fusion2= cell2mat(out{2});
fusion=[fusion1;fusion2];
In your cell matrix (out) there are 2 other cell matrix. For using cell2mat you should have normal matrix in 'out' cell matrix.
  1 件のコメント
Balaji M. Sontakke
Balaji M. Sontakke 2018 年 6 月 22 日
Sir, am having the four mat files (attached herewith), which of two contains features from minutiae and other two contains feature from invariant moment. I did classification by loading first two mat files (see following code), In your code (fusion) contains fusion of all mat files, then how i provide the value of reduced_testdata and reduced_traindata for further processing.
clear all;
clc;
tic; %%calculating elapsed time for execution
%load mat files
load('db3.mat');
load('db4.mat');
%%reshape into row vector
reduced_testdata = reshape(reduced_testdata,1,4,100);
reduced_traindata = reshape(reduced_traindata,1,4,200);
%%adjust dimension
% Adjust matrix dimension
P_test = cell2mat(reduced_testdata); % Convert cell array to matrix
P_train = cell2mat(reduced_traindata);
%%rearranges the dimensions of P_test and P_train
C = permute(P_test,[1 3 2]);
P_test = reshape(C,[],size(P_test,2),1);
C = permute(P_train,[1 3 2]);
P_train = reshape(C,[],size(P_train,2),1);
%%labeling class
train_label=load('train_label.txt'); test_label=load('test_label.txt');
%%Normalisation by Z - Scores
P_train = zscore(P_train,0,2);
P_test =zscore(P_test,0,2);
%%classfication
predictlabel = knnclassify(P_test, P_train, train_label,3,'euclidean','nearest');
cp = classperf(test_label,predictlabel);
Conf_Mat = confusionmat(test_label,predictlabel);
disp(Conf_Mat);
%%Evaluate Performance
[FPR, TPR,Thr, AUC, OPTROCPT] = perfcurve(predictlabel, test_label,1);
figure,
plot(TPR,FPR,'r-','LineWidth',4);
xlabel('False positive rate')
ylabel('True positive rate')
title('ROC Curve for Classification ')
Tbl = table(FPR, TPR,Thr)
[FPR, FNR, Thr] = perfcurve(predictlabel, test_label,1,'xCrit','fall','xCrit','miss');
Thr = Thr/10;
figure,
plot(Thr,FPR,'r--','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
xlabel('Threshold')
ylabel('False positive rate / FAR')
title('False Acceptance Rate / FAR ')
figure,
plot(Thr,FNR,'r--','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
xlabel('Threshold')
ylabel('False Negative rate / FRR')
title('False Rejection Rate / FRR ')
Tbl = table(FPR, FNR,Thr)
fprintf('\n\n Overall accuracy:%f%%\n',cp.CorrectRate*100);
%%calculating elapsed time for execution
toc

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


Andrei Bobrov
Andrei Bobrov 2018 年 6 月 22 日
編集済み: Andrei Bobrov 2018 年 6 月 22 日
fusion = cell2mat(cat(1,out{:}));
or just
V = {load('db1.mat'),load('db2.mat'),load('db3.mat'),load('db4.mat')};
n = cellfun(@fieldnames,V,'un',0);
V1 = cellfun(@(x,y)[x.(y)],V,[n{:}],'un',0);
fusion = cell2mat(reshape(cat(1,V1{:}),1200,[]));
  1 件のコメント
Balaji M. Sontakke
Balaji M. Sontakke 2018 年 6 月 22 日
Sir, how to provide this fusion to knn classification, because I required P_Test and P_train (Please see attached code)

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

カテゴリ

Help Center および File ExchangePower Converters についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by