How can l store large numbers from input in App Designer?

4 views (last 30 days)
l tried to store the inputs in a cell array. Assume l have 1000 input, the first column of array is increasing numbers from 1 to 1000, and the second column is the real inputs (big numbers). Data is stored n the cell array. Then, I take the large numbers from the number in front of them (first column) when l need to make calculations in other buttons. Is there any other way to take inputs directly with their value.
Thanks in advance.
  2 Comments
Steven Lord
Steven Lord on 14 Nov 2023
big numbers
How big are these "big numbers" (both in terms of magnitude and in terms of how many digits they have?)
piston_pim_offset
piston_pim_offset on 15 Nov 2023
They are serial numbers, and have 8 - 10 digits. l thought l can create a cell array larger than that and place them in the corresponding order ( like 123456789 is stored in X{123456789} ), but it would take so much space, so l could not do it.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 15 Nov 2023
They are serial numbers, and have 8 - 10 digits. l thought l can create a cell array larger than that and place them in the corresponding order ( like 123456789 is stored in X{123456789} ), but it would take so much space, so l could not do it.
In that case, how are you planning to use them? If you're going to hold say the quantity of the item with that serial number, instead of using a cell array I'd use a sparse column vector. If you're going to hold something more complicated than just a single number, like a struct array containing information about a part in an inventory, consider using a dictionary.
s = sparse(1357924680, 1, 42) % 42 of item 1357924680
s =
(1357924680,1) 42
s(65535, 1) = 99 % 99 of item 65535
s =
(65535,1) 99 (1357924680,1) 42
Q = s(98765) % Q = 0 means you have none of item 98765
Q =
All zero sparse: 1×1
  5 Comments
Steven Lord
Steven Lord on 16 Nov 2023
Indexing, like I showed with my sparse example.
Sparse
Let's say we had 42 units of item 1357924680. Those items are in color #1 and cost $5.99 per unit. I could store those in three columns in s.
% 42 of item 1357924680 (column 1)
% Those items are in color #1 (column 2)
% The price per item is $5.99 (column 3)
s = sparse(1357924680, 1:3, [42, 1, 5.99])
s =
(1357924680,1) 42.0000 (1357924680,2) 1.0000 (1357924680,3) 5.9900
Now if I want to add 99 units of item 65535, color #2, with a cost of $17.36 per unit.
s(65535, 1:3) = [99, 2, 17.36]
s =
(65535,1) 99.0000 (1357924680,1) 42.0000 (65535,2) 2.0000 (1357924680,2) 1.0000 (65535,3) 17.3600 (1357924680,3) 5.9900
How many units of item 98765 are in stock?
Q = full(s(98765, 1)) % Wrapping in full because the full display is nicer here
Q = 0
How many units of item 65535?
Q2 = full(s(65535, 1))
Q2 = 99
How much does each unit of item 65535 cost?
P2 = full(s(65535, 3))
P2 = 17.3600
To make the code easier to understand, you might want to define a few constants.
QUANTITY = 1;
COLOR = 2;
PRICE = 3;
howMany65535 = full(s(65535, QUANTITY))
howMany65535 = 99
Dictionary
Alternately, using a dictionary:
% Could write a function to accept this data and build the struct
item1 = struct('quantity', 42, 'color', 'red', 'price', 5.99);
item2 = struct('quantity', 99, 'color', 'green', 'price', 17.36);
d = dictionary([1357924680, 65535], [item1, item2])
d = dictionary (double --> struct) with 2 entries: 1.3579e+09 --> 1×1 struct 65535 --> 1×1 struct
infoItem65535 = d(65535)
infoItem65535 = struct with fields:
quantity: 99 color: 'green' price: 17.3600
If I sold a unit of item 65535:
infoItem65535.quantity = infoItem65535.quantity-1;
d(65535) = infoItem65535;
d(65535) % Now quantity is 98
ans = struct with fields:
quantity: 98 color: 'green' price: 17.3600
If you want to check if the dictionary has an item:
anyItem42 = isKey(d, 42) % none of item 42 in stock
anyItem42 = logical
0
Asking for an item you don't know exists (isn't in the dictionary) throws an error.
infoItem42 = d(42)
Error using ()
Key not found.
piston_pim_offset
piston_pim_offset on 16 Nov 2023
That helped me a lot, I really thank you for cour comments!

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!