restricting get method to not process all the values

1 Ansicht (letzte 30 Tage)
Micke Malmström
Micke Malmström am 28 Apr. 2021
Kommentiert: Micke Malmström am 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?

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by