A question about the declaration of public properties in apps

3 次查看(过去 30 天)
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.

回答(1 个)

Steven Lord
Steven Lord 2024-10-12
How are you planning to share the data between the two apps? This documentation page offers some guidance on how to do that.
  2 个评论
Muazma Ali
Muazma Ali 2024-10-12
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 2024-10-12
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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by