Why am I not getting printed all zones and info from one column in my table?

52 visualizzazioni (ultimi 30 giorni)
Here are the steps that lead to the results:
1) You start by running app2_tester that leads to app3_tester ( for making the problem simpler, I have just made it possible choosing just one combination of salts, NaCl KCl and ZnBr2: so that I don’t need to attach many function files, though there are listed up many salts in the listbox of app3_tester.
2) Each time you have pressed the choices for every zone, you press the button “done with the zone”, for instance when you in start have chosen that there are two zones, you first begin to selecting information for zone1 then do the same for zone 2
3) When you have finished pressing info about both zones, you press “ computed water activity and osmotic pressure” in app2_tester
I have problems in app2_tester and app3_tester. The other apps and some functions that are needed to run the apps are correct. I get error in app3_tester. So what I am wondering is:
Why am I not getting the zone nr 2 writtten in my osmotic table data that is printed out when I press on the button “display results from all zones”, and neither the names of the different combinations of salts in the column called combination_of_salts in my table?
The error I get says:
Error using table (line 231)
All input variables must have the same number of rows.
Error in app3_tester/StartanalysisButtonPushed (line 259)
app.Callingapp.Osmotisk_data(app.zone_now,:) = table(app.zone_now, app.combinations_of_salts, app.vekt_prosent_best_salt_1,app.vekt_prosent_best_salt_2, app.samlet_vannaktivitet,P,effect);
  4 Commenti
Walter Roberson
Walter Roberson il 14 Set 2025 alle 19:06
"LHS" stands for "left hand side"
"RHS" stands for "right hand side"
dpb
dpb il 15 Set 2025 alle 14:53
Modificato: dpb il 17 Set 2025 alle 14:19
As suggested, if you will set the breakpoint and look, you'll find which variable(s) aren't the same height and causing the problem. We don't have any way to know and as presented it's too complicated to try to duplicate.
The issue of using varuabke app.zone.now on both sides of the assignment isn't the cause of this error; that has to do with the creation of the table on the RHS; you'll have to fix that first by making sure all variables are the same height (number of rows).
After that, then the possible issue with the use of the same variable on both sides as an index may come up; it may be ok as is; I pointed it out for you to be sure it is what you intended as it is a somehwhat unusual construction.
You'll have to inspect the various variables at that point by setting the breakpoint and looking ot see where the logic flaw is or pare it down to something that reproduces the issue that can be looked at without somebody having to download two or three other apps and try to debug them for you....that's jsut asking an awful lot from a bunch of busy volunteers here...

Accedi per commentare.

Risposte (2)

dpb
dpb il 7 Set 2025 alle 15:07
Spostato: dpb il 15 Set 2025 alle 17:40
Set a breakpoint at line 259(*) so it will stop before it fails. Then you can poke at the data values there...you'll find which are/aren't the same height and be able to track down why isn't what is expected.
Or, learn to use dbstop to control the debugger, here all you would need would be to execute
dbstop if error
at the command line before punching the button that causes the error.
Error using table (line 231)
All input variables must have the same number of rows.
Specifically, the error is telling you that in
app.Callingapp.Osmotisk_data(app.zone_now,:) = table(app.zone_now, ...
app.combinations_of_salts, ...
app.vekt_prosent_best_salt_1, ...
app.vekt_prosent_best_salt_2, ...
app.samlet_vannaktivitet, ...
P, ...
effect);
that at least one of the seven (7) variables in the argument list to table() is not the same as the others; a table can only be constructed from variables that have the same number of rows.
It's puzzling that variable app.zone_now is used as an indexing variable on the LHS and as a variable entered into the table on thee RHS; this may be what was intended, but make sure those are what you really intended them to be as well.

Image Analyst
Image Analyst il 14 Set 2025 alle 15:23
In your call to table, all variables that comprise the table must have the same number of rows. It's saying that not all of your variables have the same number of rows. This a very common error. It's highly likely that one of the vectors is not a column vector (N-by-1) but is a scalar, or a row vector (1-by-M). Check the sizes. If one is a row vector, reshape it using ', like instead of vec use vec' instead. Pseudocode:
t = table(colVec, rowVec'); % The ' will transform rowVec from a row vector into a column vector.
That will transpose rowVec. colVec is already a matrix or column vector.
If one of the variables given to table is a scalar (single number) then multiply it by ones to get the required number of rows. Like
sz = size(cv);
where cv is a column vector or matrix of the desired number of rows. Then make your scalar a column vector like this;
v = v * ones(sz(1), 1); % v will now have sz(1) number of rows and one column.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by