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 个评论
Guillaume
Guillaume 2014-9-5
@ Adam: Yes you're right. Actually I am not an expert at all in classes. I don't know when and how to use them properly. That's why sometimes I am making things complicated when I could make them easy...
Adam
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
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
Guillaume 2014-9-3
It's another question entirely, you should have started a new question really.
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);
Guillaume
Guillaume 2014-9-5
OK thank you. Next time I will open a new question as you suggest.

请先登录,再进行评论。

更多回答(1 个)

Matt J
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

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by