Filter löschen
Filter löschen

A question about the declaration of public properties in apps

20 Ansichten (letzte 30 Tage)
Muazma Ali
Muazma Ali am 12 Okt. 2024 um 14:05
Kommentiert: Steven Lord am 12 Okt. 2024 um 16:42
Hi! :)
I have a question: if I have declared a property as a public variable in my main app, is it necessary that I also declare it as a private property in the app I am using it.
In my case I have a table Osmotisk_data that I have declared as a public property in the main app, then I am using some of the columns (arrays) from this table in another app, there I have declared it as a private property, but I am a little confused becuase I am not getting the results that I am supposed to get.

Antworten (1)

Steven Lord
Steven Lord am 12 Okt. 2024 um 15:46
How are you planning to share the data between the two apps? This documentation page offers some guidance on how to do that.
  2 Kommentare
Muazma Ali
Muazma Ali am 12 Okt. 2024 um 16:18
I didn't understand your question: isnt the data automatically shared when I declare the variable as public in the main app..?
Steven Lord
Steven Lord am 12 Okt. 2024 um 16:42
Anyone with access to the app object has access to its public properties. But are you giving that second app access to that first app object?
As a non-app example, I'll create a variable R. Don't worry too much about the details of what it is. What's important is that it's an object.
R = RandStream.create('mt19937ar');
It has properties that I can get since I have access to the object.
p = properties(R)
p = 9x1 cell array
{'Type' } {'Seed' } {'NumStreams' } {'StreamIndex' } {'State' } {'Substream' } {'NormalTransform'} {'Antithetic' } {'FullPrecision' }
S = R.Seed
S = uint32 0
But if I call a function and don't give it the object, it can't ask for properties of the object even though they're public. It has no idea what R is, even though it exists in the calling workspace. It didn't get passed into the myfun workspace.
myfun() % will error, doesn't know what R is
Inside function myfun, trying to get the Seed property from R
Unable to resolve the name 'R.Seed'.

Error in solution>myfun (line 7)
y = R.Seed; % will error
function myfun
disp("Inside function myfun, trying to get the Seed property from R")
y = R.Seed; % will error
end
That documentation page I linked to gives some guidance about how to make the first app object accessible to the second app.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by