A question about the declaration of public properties in apps

조회 수: 3 (최근 30일)
Muazma Ali
Muazma Ali 2024년 10월 12일
댓글: Steven Lord 2024년 10월 12일
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