- When you load the mat file, the function that handle points to must be on the path.
- If a different function with the same name is on the path when you load the mat file, that function will be called instead.
Function handle in structure field generating data from other fields
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Maximilian Rüppell
le 8 Avr 2019
Modifié(e) : Maximilian Rüppell
le 9 Avr 2019
Hi everyone,
I have a structure and in one of its fields I want to store some data. It is large data, but generation of it is very fast. Since the structure needs to be saved as matfile, generating the data when needed (i.e. when accessing the struct field) would be much better than storing it with the struct. Is this possible to solve this, maybe with function handles?
Lets assume a function
function[DataOut]=MyFunction(Locs, Peaks)
% some random stuff happening to generate DataOut
end
and a struct with the fields
MyStruct.Locs=[1 3 5 7 9];
MyStruct.Peaks=[40 50 60 70 80];
MyStruct.ProcessedData=@MyFunction
Is is somehow possible to just access the field MyStruct.ProcessedData and to get the data that have been produced by using the fields "MyStruct.Locs" and MyStruct.Peaks" ? That means that I would have to tell the function handle which data to use when making the handle... But how?
I think this is close to something like object oriented programming and a special method invoked when trying to access a field. But I have not much knowledge about this kind of topics. You help is very much appreciated!
Thanks in advance!
6 commentaires
Réponse acceptée
Guillaume
le 8 Avr 2019
With a structure, it's not possible to do what you want.
classdef DemoClass
properties
Locs;
Peaks;
end
properties (Dependent)
SomethingElse;
end
methods
function value = get.SomethingElse(this)
%code to calculate SomethingElse.
end
end
end
SomethingElse will be calculated every time it is accessed by the user.
1 commentaire
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!