restricting get method to not process all the values
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt J
2021-4-28
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!