formatting to excel and inputting data into a matrix (???)

3 vues (au cours des 30 derniers jours)
Zachary Hunsicker
Zachary Hunsicker le 12 Avr 2021
I am making a program that in completion will show a piechart with diffrering materials and the amount of stock left over. the thing i am stuck on is I ask the user to firist put in how many diiffrent materials there are i have that done and an increasing counter for future use. what i don't know how to do is how to get the user to be able to input the name of the material, how much of that material there is to work with and then for future use be able to change the amount of material left as the material wouldbe used up and show a percent of remaing material compared to the original.. I want this to be able to go to an excel file but. i don't know how i am going to input the datafrom the user and then change the row so that they can do the process again with the next material. repeating until they reach the amount of materials they declared at the begining of the program. can someone please help I will post what a mess of code i have been experimenting on bellow.
numMat=input('Please enter the number of differing materials: ');%asks for number of materials differing
while numMat <= 0
fprintf('Entered number was not postive.\n')
numMat=input('Please enter the number of differing materials: ');%asks for number of materials differing
end
datasheet(numMat);
a = rand(numMat,1); % original data vector "a"
pie(a);
hold on; % plot subsequent data on same axes
b = rand(numMat,1); % new data vector "b"
clf('reset') % clear current figure axes
pie(b) % redraw PIE with new data vector b
linkdata on;
drawnow; % draw immediately and clear handle queue
hold off; % henceforth, create new axes
Function Datasheet
function datasheet(numMat)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
counter=1;
Matnum= [1,numMat];
name= {1,numMat};
MatCT= [1,numMat];
MatCC= [1,numMat];
T =table(Matnum,name,MatCT,MatCC);
T.Properties.RowNames = names;
while counter <= numMat
MatCT=input('Please enter the number of materials for material (name): ');
counter=(counter +1);
end
end

Réponses (1)

Ishaan Mehta
Ishaan Mehta le 4 Mar 2024
Hi Zachary,
Since your application involves multiple stages of user input and processing, I feel creating an interactive application using MATLAB App Designer will really suit this use-case. It will allow you to create a user-interface that will help in breaking down the whole workflow into a multi-part experience.
Here's an outline of the development steps you can expect while following this approach:
1. Planning the app layout
Design the interface using App Designer's drag-and-drop layout editor. Below are some UI components you'll need:
  • An input field for the user to specify the number of different materials.
  • A button to confirm the number of materials and initiate the input sequence.
  • Dynamic input fields for entering the name of the material and the amount available. These can be generated based on the number of materials specified.
  • A button to submit each material's data.
  • An area to display the pie chart.
  • Multiple tabs to split the process into sections
Buttons can be built using the "uibutton" component, text fields for inputs can use "uieditfield", "uiaxes" can be used to plot the required pie-charts, and "uitabgroup" to created a tab-based layout.
The following MathWorks documentation page enlists all the available UI components you can leverage while desgining your app:
2. Initializing variables
In the "startupFcn" callback, initialize variables to store material names, original amounts, and current amounts. These could be arrays or a table, depending on your preference.
Refer to the following page for more information about this callback function:
3. Capturing user input and updating data later
Use the "ValueChangedFcn" callback of the edit fields to capture the number of materials in a variable. Upon confirming the number of materials, dynamically generate input fields for material names and amounts, or alternatively, display a pre-made but initially hidden panel with these fields.
Use "ButtonPushedFcn" callback of the "uibutton" elements to trigger your logic when user presses a button. This can be used to submit the entered values or refresh the pie-chart.
Provide a mechanism for users to update the amount of material left (e.g., through a table or individual input fields). Use callbacks to update your data structure whenever changes are made.
4. Displaying the pie chart
Use the "pie" function within a UIAxes component to display the pie chart. You might need to preprocess your data to get the current amounts of each material. Every time the material amounts are updated, redraw the pie chart to reflect these changes.
For more information, here's documnetation for the "pie" fucntion in MATLAB:
5. Exporting to an Excel file
Use the "writetable" function to export your data to an Excel file. Ensure your data is in a table format for this step. You can add a button specifically for this export functionality.
I hope this provides you with a general outline on how to get started with developing your application.
Good luck!

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by