set object property of a user-defined class
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I want to set the properties "nb_pixel_horiz" and "nb_pixel_verti" of an object "p" that has the user-defined class "Picture".
I wrote
classdef Picture
properties
nb_pixel_horiz;
nb_pixel_verti;
end
methods
end
end
And I want to write in the main command something like:
p = Picture;
set(p,'nb_pixel_horiz', 2000);
set(p,'nb_pixel_verti', 1000);
But it does not work. Could someone help me?
Thanks! Guillaume
댓글 수: 4
Adam
2014년 9월 5일
In case you have not yet come across it, the following document provides an excellent reference for helping to understand programming with classes in Matlab. I still refer back to it on many occasions:
채택된 답변
Guillaume
2014년 9월 3일
편집: Guillaume
2014년 9월 3일
Hey, Another Guillaume!
You need to derive from hgsetget, so:
classdef Picture < hgsetget
properties
nb_pixel_horiz;
nb_pixel_verti;
end
end
댓글 수: 3
Guillaume
2014년 9월 3일
It's another question entirely, you should have started a new question really.
get on array of object returns a cell array (or sometimes a struct, see http://www.mathworks.co.uk/help/releases/R2014a/matlab/matlab_oop/implementing-a-set-get-interface-for-properties.html#bs2pctb)
One way of doing what you want, assuming all pictures have the same size:
I = get(p(1:10),'intensity_values');
I = reshape(cell2mat(I), size(I{1}, 1), size(I{1}, 2), []); %transform into 3d matrix
pixstd = std(I, 0, 3);
추가 답변 (1개)
Matt J
2014년 9월 3일
Unless you really need handle semantics, it would be enough to do
p.nb_pixel_horiz=2000
p.nb_pixel_verti=1000
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!