How can l store large numbers from input in App Designer?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
piston_pim_offset
il 14 Nov 2023
Commentato: piston_pim_offset
il 16 Nov 2023
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 Commenti
Steven Lord
il 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?)
Risposta accettata
Steven Lord
il 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(65535, 1) = 99 % 99 of item 65535
Q = s(98765) % Q = 0 means you have none of item 98765
5 Commenti
Steven Lord
il 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])
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]
How many units of item 98765 are in stock?
Q = full(s(98765, 1)) % Wrapping in full because the full display is nicer here
How many units of item 65535?
Q2 = full(s(65535, 1))
How much does each unit of item 65535 cost?
P2 = full(s(65535, 3))
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))
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])
infoItem65535 = d(65535)
If I sold a unit of item 65535:
infoItem65535.quantity = infoItem65535.quantity-1;
d(65535) = infoItem65535;
d(65535) % Now quantity is 98
If you want to check if the dictionary has an item:
anyItem42 = isKey(d, 42) % none of item 42 in stock
Asking for an item you don't know exists (isn't in the dictionary) throws an error.
infoItem42 = d(42)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!