restricting get method to not process all the values
4 views (last 30 days)
Show older comments
Micke Malmström
on 28 Apr 2021
Commented: Micke Malmström
on 28 Apr 2021
I have a get method that calulates a 2-d matrix based on data in a 3d-matrix. This calculation takes some time to perform if I have allot of data in the object.
function out = get.FWHM(obj)
for RowNo=1:obj.NRows
for ColumnNo=1:obj.NColumns
out(RowNo,ColumnNo)=fwhmFunctionGivingSingleValueOut( obj.Data(RowNo,ColumnNo,:) );
end
end
end
I've tried to restrict the rows and columns to be process, when I dont need to have all the values calculated, like this:
function out = get.FWHM(obj,RowIND,ColIND)
for RowNo=RowIND
for ColumnNo=ColIND
out(RowNo,ColumnNo)=fwhmFunctionGivingSingleValueOut( obj.Data(RowNo,ColumnNo,:) );
end
end
end
But Matlab doesnt like that. In principle I could place some property in the obj that keep strack of the rows and columns to operate on, but that does not seem like the best way to do it
What is the best way to restrict the get-method to only process some of the values?
0 Comments
Accepted Answer
Matt J
on 28 Apr 2021
There doesn't seem to be a good reason for this to be a get method. Just use a regular method.
function out = FWHM(obj,RowIND,ColIND)
for RowNo=RowIND
for ColumnNo=ColIND
out(RowNo,ColumnNo)=fwhmFunctionGivingSingleValueOut( obj.Data(RowNo,ColumnNo,:) );
end
end
end
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!