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 view (last 30 days)
%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 Comments
Kalai Arasi Mehavarnam
Kalai Arasi Mehavarnam on 17 Oct 2018
That problem occurred for me too and when I copied to another fresh script, it was OK but still the variables was not saved

Sign in to comment.

Accepted Answer

Stephan
Stephan on 17 Oct 2018
Edited: Stephan on 17 Oct 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 Comments
Kalai Arasi Mehavarnam
Kalai Arasi Mehavarnam on 17 Oct 2018
I did as you said in here, what you see is my previous uncorrected code.As per your suggestion after assigning them in output function, its working and now the work space has all the variables. Thank you so much

Sign in to comment.

More Answers (0)

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!