I am not sending the functions that are needed to run the app and neither the other app required to run the app since they are many functions and the problem is in tester_app_3.
Do I need a while loop somewhere?
Seems the values for the table osmotic data aren’t saved in my table columns when I run the app?
I think there is something missing in tester_app_3 which I can’t see.
Do I need a loop to accumulate the column values in osmotic data, I just get the last value printed. It also seems that the program doesn’t start on zone nr 1 when I start the app again though I have deleted the previous files by writing the syntax delete(file).
I have matlab 2018

8 Kommentare

Voss
Voss am 3 Mär. 2024
Please provide all the code (apps and m-files) needed to run the app, and please describe the steps necessary to reproduce the problem.
Muazma Ali
Muazma Ali am 18 Mär. 2024
There are many things that are not correctly coded in tester_app_3 :
( I am attaching the other files that are necessary to run tester_app_3 but there is nothing wrong with them)
  1. I shortened the code so you just have the possibility to choose two types of combination from the listbox in tester_app_3: CaCl2 MgCl2 ZnBr2 and NaCl2 KCl ZnBr2.
  1. When I start the tester_app_2 that leads me to tester_app_3, I choose the nr of zones to be 3 and the nr of salts to be 3. Then I choose this salt combination CaCl2 MgCl2 ZnBr2 and choose ME.
  1. As you can see , the program is not accumulating osmotic_table results since I am getting zeros in all rows instead of my results. I am supposed to get three rows as I had chosen nr of zones to be 3.
  1. Since I have this code in tester_app_3
delete('Osmotic_data.xls')
writetable(app.Osmotisk_data,'Osmotic_data.xls','Sheet',1);
It was supposed to overwrite the content in my osmotic_data file but I don’t think it is doing that since I am getting 8 rows and the zone_number which is supposed to start at 1 each time is not starting at 1
5. There is also something wrong in the for loop in visualiseringsapp_2-1_tester. I am getting this error:
No appropriate method, property, or field 'antall_soner' for class
'visualiseringsapp2_1_tester'.
Error in visualiseringsapp2_1_tester/SwitchValueChanged (line 43)
for i = 1:app.antall_soner
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 378)
----------------------------------------------------------------------------------
antall_soner is a public property from tester-app2 that I am using but I am unsure how to declare that variable in visualiseringsapp_2-1_tester
Error while evaluating Switch PrivateValueChangedFcn.
6. I also want points instead of a graph as an outcome of tester_visualiseringsapp but it is not happening..
Muazma Ali
Muazma Ali am 18 Mär. 2024
I am sorry by mistake I deleted one file that is necessary to run tester_app_3 and since I have reached the limit I cant upload it now, will do it tomorrow.
If it is possible for you to tell me how I can correct tester_app-3 with just the discription I have given , kindly tell me
Voss
Voss am 18 Mär. 2024
You can avoid the limit tomorrow by zipping all the necessary m-files into a single zip file and uploading the zip file.
Muazma Ali
Muazma Ali am 19 Mär. 2024
Hi! :)
Now I am just copying my previous comment in here with all the necessary files in a zipfile as you recommended.
There are many things that are not correctly coded in tester_app_3 :
( I am attaching the other files that are necessary to run tester_app_3 but there is nothing wrong with them)
  1. I shortened the code so you just have the possibility to choose two types of combination from the listbox in tester_app_3: CaCl2 MgCl2 ZnBr2 and NaCl2 KCl ZnBr2.
  1. When I start the tester_app_2 that leads me to tester_app_3, I choose the nr of zones to be 3 and the nr of salts to be 3. Then I choose this salt combination CaCl2 MgCl2 ZnBr2 and choose ME.
  1. As you can see , the program is not accumulating osmotic_table results since I am getting zeros in all rows instead of my results. I am supposed to get three rows as I had chosen nr of zones to be 3.
  1. Since I have this code in tester_app_3
delete('Osmotic_data.xls')
writetable(app.Osmotisk_data,'Osmotic_data.xls','Sheet',1);
It was supposed to overwrite the content in my osmotic_data file but I don’t think it is doing that since I am getting 8 rows and the zone_number which is supposed to start at 1 each time is not starting at 1
5. There is also something wrong in the for loop in visualiseringsapp_2-1_tester. I am getting this error:
No appropriate method, property, or field 'antall_soner' for class
'visualiseringsapp2_1_tester'.
Error in visualiseringsapp2_1_tester/SwitchValueChanged (line 43)
for i = 1:app.antall_soner
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 378)
----------------------------------------------------------------------------------
antall_soner is a public property from tester-app2 that I am using but I am unsure how to declare that variable in visualiseringsapp_2-1_tester
Error while evaluating Switch PrivateValueChangedFcn.
6. I also want points instead of a graph as an outcome of tester_visualiseringsapp but it is not happening..
Voss
Voss am 19 Mär. 2024
Thank you for the files.
I followed the instructions:
  1. Run tester_app2.mlapp
  2. Enter 3 for Nr of zones and 3 for Nr of salts
  3. Click Choose salts! button
  4. Selected CaCl2, MgCl2, and ZnBr2
  5. Clicked Start_analysis button
At that point, I got an error that "beregn_ionic_strength_best_salts_CaCl2_MgCl2_ZnBr2" was not defined, on line 235 of "Amongst_CaCl2_MgCl2_ZnBr2_test.m". Noticing there was an m-file called "beregn_ionic_strength_best_salts_CaCl2_MgCl2_ZnBr2_tester.m", I made a copy of that and renamed the copy "beregn_ionic_strength_best_salts_CaCl2_MgCl2_ZnBr2.m", then clicked the Start_analysis button again.
This time I got an error that "vannaktivitet_best_salt_1" is not defined, on line 146 of "beregn_ionic_strength_best_salts_CaCl2_MgCl2_ZnBr2.m". Indeed, that variable is not defined anywhere in that file [but it is defined in "Amongst_CaCl2_MgCl2_ZnBr2_test.m" (under certain conditions at least) and in "Amongst_NaCl_KCl_ZnBr2_test.m" (under certain conditions at least)].
Muazma Ali
Muazma Ali am 19 Mär. 2024
sorry probably I forgot to attach all the files that were needed.
I will try again later, :)
Muazma Ali
Muazma Ali am 20 Mär. 2024
Hi again! :)
And sorry for the confusion; now all the right files for the test version are included in the zip file,
I am not pasting the description of the problem but the problems are the same as described above
Thanks for helping me

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Voss
Voss am 20 Mär. 2024

1 Stimme

In order to fix the problems you're having, it is necessary to redesign the code significantly.
I gather that your intent is to run tester_app_3 for each zone, and collect the results in a single table. To do that, I made the table Osmotisk_data a property of tester_app2 (i.e., the main app), and removed the reliance on writing and reading the xls file (you can add a new button to write the file if desired).
Each time tester_app_3 is complete (by clicking on the Done button - formerly the Exit button), the zone_now property of tester_app2 is incremented so that the next call to tester_app_3 updates the correct row of the table. This was the essential logic missing in your original design.
See the attached zip containing the updated files. All mlapp files were modified, but no m files were modified.
I tried to keep your existing logic the same as much as possible, though I did add some new error-checking including disabling buttons to prevent entry into the next step with invalid parameters (and enabling them when the parameters are valid). I'm not going to claim that the program is now 100% robust, but it should be an improvement.
Some general advice for the future:
  • Do not to make a variable an app property unless it's necessary to do so. Generally it's only necessary if that variable needs to be shared among multiple apps (in which case it must be a public property) or multiple functions within one app (in which case it can be a private property). I found that most of your app properties were really only needed in one function, so those have been made into local variables in the function where they are used. You can see the list of app properties now to get an idea of the very few really necessary app properties in each app, and understand why those particular things need to be app properties.
  • Error-check and validate a variable value before storing it as an app property. It makes your programming job easier if you know your app properties are always valid (and consistent with each other).
  • In general, think about what the program needs to do when the user entered something invalid. Arguably more important than (as least equally as important as) doing the right thing when a good value is entered is not doing the wrong thing (i.e., crashing / generating an uncaught error) when a bad value is entered. In designing GUIs you have to give plenty of thought to all the bad states the program can get into, not only the one good state where everything is fine.
Let me know if you have any trouble opening the mlapp files in your version of appdesigner. Sources I've found online seem to suggest there should be no compatibility issues between R2022a (what I used to save them) and your version (R2018a or R2018b), but if there are issues, let me know.

16 Kommentare

Muazma Ali
Muazma Ali am 7 Apr. 2024
Thanks a lot, I am now trying to understand what and how you have made the changes..
I have two questions.
Can you please explain the code in the picture that I have attached ( I didnt understand what you did here..)
In addition I am not getting the dots on my plot as I wanted to get but a line plot which I dont want
Voss
Voss am 7 Apr. 2024
Bearbeitet: Voss am 7 Apr. 2024
You're welcome!
Here's an explanation of that code:
% take the first zone_now rows of table Osmotisk_data from the calling app,
% and store it as local variable T for convenience:
T = tester_app3.Callingapp.Osmotisk_data(1:tester_app3.Callingapp.zone_now,:);
% put T in this app's uitable, app.UITable:
app.UITable.Data = T;
% make app.UITable column names the same as T's column names:
app.UITable.ColumnName = T.Properties.VariableNames;
% plot Osmotic_pressure vs Total_water_activity (both from table T, i.e.,
% the first zone_now rows of Osmotisk_data from the calling app) in app.UIAxes:
x = T.Total_water_activity;
y = T.Osmotic_pressure;
plot(app.UIAxes,x,y,'.-')
Change '.-' to '.' if you want to see only dots at the data points with no line connecting them. (See here for more options.)
Muazma Ali
Muazma Ali am 17 Mai 2024
@Voss Hi! :)
I am now attaching 2 apps here.
There is something wrong in the declaration of the startup function in visualiseringsapp. And I dont understand whats wrong. I get the following error message:
Error using visualiseringsapp/startupFcn (line 26)
Not enough input arguments.
-------------------------------------
Visualiseringsapp is supposed to use visualiseringsapp2 (where best_Osmotic_data is defined). And visualiseringapp is called by app3 which is similiar to tester_app_3, the one I attached earlier some weeks ago with some other files.
Voss
Voss am 18 Mai 2024
The StartupFcn of visualiseringsapp is:
% Code that executes after component creation
function startupFcn(app, app3, visualiseringsapp2)
app.Callingapp=app3;
app.best_Osmotisk_data_1=visualiseringsapp2.best_Osmotisk_data_1;
end
The function declaration line
function startupFcn(app, app3, visualiseringsapp2)
indicates that the function takes two arguments, app3 and visualiseringsapp2. If you call visualiseringsapp with fewer than 2 arguments you'll get that error.
Muazma Ali
Muazma Ali am 19 Mai 2024
@Voss Hi again! :)
But I am using these two inputs in visualiseringsapp as you can see..
So why am I getting this error?
Voss
Voss am 19 Mai 2024
I don't see visualiseringsapp or visualiseringsapp2 called anywhere in either .mlapp file.
Muazma Ali
Muazma Ali am 22 Jun. 2024
Hi again!@Voss I am working with the same apps.
In my apps, tester_app_2 leads to tester_app3.
There I have to choose salts. I have shortened my program so that it is easier for you people to help me; it is just possible to choose two combinations of salts when you have the possibility to choose salts , either you can choose CaCl MgCl2 ZnBr2 or NaCl KCl ZnBr2.
Then I do what the program instructs me to do, and push on Done, then if I have chosen 2 zones I repeat the procedure for the second zone by clicking on choose zone 2 salts.
The problem is that when I have done this and whatever I am instructed to do afterwards and then push on 'display all results', I dont get any plot showing all results..that is supposed to appear right beneath the table showing all results.
Thanks for helping me, :)
Voss
Voss am 1 Jul. 2024
Bearbeitet: Voss am 1 Jul. 2024
Do you have to click the "Start analysis" button at some point in the process? When I do that, I get the error:
"Unrecognized function or variable 'sett_temperatur'.
Error in beregn_maks_vektprosent_lost_1 (line 62) temperatur=sett_temperatur();"
Muazma Ali
Muazma Ali am 2 Jul. 2024
@Voss Hi! :)
I am sorry. Probably I forgot to attach the file containing the function sett_temperatur.
I have now included it in the folder:) Hope it works now.
Voss
Voss am 2 Jul. 2024
Now the error is:
Unrecognized function or variable 'vektprosent_funksjoner'.
Error in beregn_maks_vektprosent_lost_1 (line 156)
maks_vektprosent_lost_CaCl2=vektprosent_funksjoner('CaCl2', temperatur)
Muazma Ali
Muazma Ali am 2 Jul. 2024
Sorry again, :(
Voss
Voss am 2 Jul. 2024
Unrecognized function or variable 'beregn_osmotisk_trykk'.
Error in tester_app_3/StartanalysisButtonPushed (line 208)
Muazma Ali
Muazma Ali am 3 Jul. 2024
@Voss Hi Voss ! :)
I have now gone through all function files and made sure that you have got all the relevant files now.
My problem now is that I am not getting the warning 'there is no zones with osmotic pressures greater than or equal to 120MPa', which I am supposed to get when I am through all the instructions as I described earlier , I just get an error saying 'not enough input arguments'.
Here is the procedure to use the apps :
In my apps, tester_app_2 leads to tester_app3.
There I have to choose salts. I have shortened my program so that it is easier for you people to help me; it is just possible to choose two combinations of salts when you have the possibility to choose salts , either you can choose CaCl MgCl2 ZnBr2 or NaCl KCl ZnBr2.
Then I do what the program instructs me to do, and push on Done. Then if I have chosen 2 zones earlier, I repeat the procedure for the second zone by clicking on choose zone 2 salts from the app window for tester_app_2.
Then I click on the different buttons, I get all the results for all zones, but when I click 'plot best results ' I get an error as I wrote above here saying 'not enough input arguments'
Voss
Voss am 3 Jul. 2024
In tester_app_3/PlotbestresultsButtonPushed you call tester_visualiseringsapp like this:
tester_visualiseringsapp(app)
That calls tester_visualiseringsapp with one input (app, which refers to the tester_app_3 object, because that line is in tester_app_3). That input becomes the second input in tester_visualiseringsapp/startupFcn
% Code that executes after component creation
function startupFcn(app, tester_app3, tester_visualiseringsapp2)
app.Callingapp=tester_app3;
app.best_Osmotisk_data_1=tester_visualiseringsapp2.best_Osmotisk_data_1;
end
because the first argument of a startupFcn is the app itself (i.e., the app in which the startupFcn is running, i.e., the app which is starting up). Additional arguments passed to the starting-up app from outside (e.g., another app which is calling the starting-up app) become the second and subsequent arguments. Here the second argument is named tester_app3, which is a good name because that argument is the tester_app_3 object, as mentioned before.
Now, the problem is that you are not passing a second argument to tester_visualiseringsapp from tester_app_3/PlotbestresultsButtonPushed.
tester_visualiseringsapp(app)
% ^^^^^^^^ no second argument passed to tester_visualiseringsapp
but tester_visualiseringsapp/startupFcn expects another argument (which is tester_visualiseringsapp2)
% Code that executes after component creation
function startupFcn(app, tester_app3, tester_visualiseringsapp2)
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^ third argument expected here
app.Callingapp=tester_app3;
app.best_Osmotisk_data_1=tester_visualiseringsapp2.best_Osmotisk_data_1;
end
so you get the error when the code in tester_visualiseringsapp/startupFcn tries to refer to its third input (tester_visualiseringsapp2), which was not given.
Not enough input arguments.
Error in tester_visualiseringsapp/startupFcn (line 26)
app.best_Osmotisk_data_1=tester_visualiseringsapp2.best_Osmotisk_data_1;
Error in tester_visualiseringsapp>@(app)startupFcn(app,varargin{:}) (line 103)
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
Error in matlab.apps.AppBase/runStartupFcn (line 69)
ams.runStartupFcn(app, startfcn);
Error in tester_visualiseringsapp (line 103)
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
Error in tester_app_3/PlotbestresultsButtonPushed (line 277)
tester_visualiseringsapp(app)
Now, tester_visualiseringsapp2 is the app that is called when you click the "Display best results in a table" button. tester_visualiseringsapp relies on tester_visualiseringsapp2 existing so that tester_visualiseringsapp can use tester_visualiseringsapp2's best_Osmotisk_data_1 property, so you better make sure that the user clicked the "Display best results in a table" button (and didn't subsequently close the window that pops up) before clicking the "Plot best results" button. (Or at least handle the case that tester_visualiseringsapp2 doesn't exist without error.) That may be tricky to do robustly, but it should be possible, e.g., by disabling the "Plot best results" button initially and then enabling it when the "Display best results in a table" button is clicked and re-disabling it when tester_visualiseringsapp2 is closed.
If you want to go down that path, have at it, but I would suggest a better alternative is to simplify/clarify as much as possible the design of your suite of apps. For instance, why are the results buttons (which show results for all zones, if I understand correctly) located in a window whose intent is to choose salts for one specific zone? This makes it necessary to select the "Choose Zone 2 salts!" button again to see the results for all zones, if you had already closed the salt selection window by selecting "Done!". It makes more sense to me for the results buttons all to be in tester_app_2, rather than tester_app_3.
Of course that wouldn't solve the problem of tester_visualiseringsapp relying on the existence of tester_visualiseringsapp2. To solve that, maybe combine all the results-displaying apps into a single app, so they don't have any interdependence that may be broken (if one exists, they all exist, because they are one and the same - much simpler).
Following that same logic, why have multiple apps at all? Why not put everything into one app?
Muazma Ali
Muazma Ali am 7 Jul. 2024
@Voss Thanks Voss! :)
I will try now and implement your suggestion to have all results button procedures in one app, and having these on the same window as app2
Muazma Ali
Muazma Ali am 8 Jul. 2024
@Voss Hi Voss ! :)
I have now made some changes; now all the results button are in the primary app , tester_app_2.
But I have a problem; I dont want the 'results of the analysis' button to appear before all the analysis are done. I have done it so all the results buttons in the panel are hidden before we push the 'results of the analysis' button.
Thanks for helping me

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Muazma Ali
Muazma Ali am 21 Dez. 2024

0 Stimmen

I have edited my appps quite much and now I am having a problem related to one app.
I am attaching all the relevant apps, the short version of them and the function files. When I run the apps which are supposed to be run in this order, I get error saying
' Error using tester_app3/StartanalysisButtonPushed (line 231)
Conversion from cell failed. Element 1 must be convertible to a string scalar.'
The order in which the apps have to be run is:
1) Run tester_app_2 which leads to tester_app_3
2) Choose three salts by pushing choose salts button ( in this short version of app you can only choose these two combinations: CaCl2MgCl2ZnBr2, NaClKClZnBr2
3) Then choose temperature and then the parameter called ME
4) Then click on Done with the zone, and push choose zone 2 salts button in tester_app_2
Then you will get the mentioned error.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Mär. 2024

Beantwortet:

am 21 Dez. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by