None of the output variables are saved in workspace,when running by function, but saves when running without function (by directly assigning input data in script)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kalai Arasi Mehavarnam
am 16 Okt. 2018
Kommentiert: Stephan
am 17 Okt. 2018
%function m =feature(x,N)
x=tr_data(1:8,:);
N=8;
[row col]=size(x)
rre=zeros(32,32,5);
for i=1:1:row
r=x(:,1:1024);
g=x(:,1025:2048);
b=x(:,2049:3072);
rre(:,:,i)=reshape(r(i,:),32,32);
gre(:,:,i)=reshape(g(i,:),32,32);
bre(:,:,i)=reshape(b(i,:),32,32);
if N==4
r1(:,:,i)=mat2cell(rre(:,:,i),[32/2,32/2],[32/2,32/2])
g1(:,:,i)=mat2cell(gre(:,:,i),[32/2,32/2],[32/2,32/2])
b1(:,:,i)=mat2cell(bre(:,:,i),[32/2,32/2],[32/2,32/2])
elseif N==8
r1(:,:,i)=mat2cell(rre(:,:,i),[32/4,32/4,32/4,32/4],[32/2,32/2])
g1(:,:,i)=mat2cell(gre(:,:,i),[32/4,32/4,32/4,32/4],[32/2,32/2])
b1(:,:,i)=mat2cell(bre(:,:,i),[32/4,32/4,32/4,32/4],[32/2,32/2])
elseif N==16
r1(:,:,i)=mat2cell(rre(:,:,i),[32/4,32/4,32/4,32/4],[32/4,32/4,32/4,32/4])
g1(:,:,i)=mat2cell(gre(:,:,i),[32/4,32/4,32/4,32/4],[32/4,32/4,32/4,32/4])
b1(:,:,i)=mat2cell(bre(:,:,i),[32/4,32/4,32/4,32/4],[32/4,32/4,32/4,32/4])
elseif N==32
r1(:,:,i)=mat2cell(rre(:,:,i),[32/8,32/8,32/8,32/8,32/8,32/8,32/8,32/8],[32/4,32/4,32/4,32/4])
g1(:,:,i)=mat2cell(gre(:,:,i),[32/8,32/8,32/8,32/8,32/8,32/8,32/8,32/8],[32/4,32/4,32/4,32/4])
b1(:,:,i)=mat2cell(bre(:,:,i),[32/8,32/8,32/8,32/8,32/8,32/8,32/8,32/8],[32/4,32/4,32/4,32/4])
else
disp('invalid N');
end
end
[sz1,sz2,sz3] = size(r1);
[sz4,sz5,sz6] = size(g1);
[sz7,sz8,sz9] = size(b1);
data=sz1*sz2*sz3;
datagreen=sz4*sz5*sz6;
datablue=sz7*sz8*sz9;
%fr=zeros(2,2,5);
fr=zeros(sz1*sz2,sz3);
fg=zeros(sz4*sz5,sz6);
fb=zeros(sz7*sz8,sz9);
for k=1:sz1
% for l=1:sz2
for m=1:data
fr(m)=mean2(r1{m});
fg(m)=mean2(g1{m});
fb(m)=mean2(b1{m});
end
end
fr=fr';
fg=fg';
fb=fb';
end
4 Kommentare
madhan ravi
am 17 Okt. 2018
Bearbeitet: madhan ravi
am 17 Okt. 2018
after running this function , my Matlab crashed no variables are saving in my workspace now
Akzeptierte Antwort
Stephan
am 17 Okt. 2018
Bearbeitet: Stephan
am 17 Okt. 2018
Hi,
if i assume you want fr, fg and fb as result in workspace change the function declaration to:
function [fr, fg, fb] = feature (x,N)
If this is done call the function the following way:
[fr, fg, fb] = feature (x,N)
Then you get the 3 variables as result to workspace.
By the way: I saw that you have got answers that worked for you. Please accept helpful answers in order to help people with similar Problems find helpful answers. Also this is somehow a kind of reward for the volunteer contributers here, which solve problems.
Best regards
Stephan
7 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!