フィルターのクリア

Print data between two inputs, to a new txt file

1 回表示 (過去 30 日間)
Brandon Kostelnik
Brandon Kostelnik 2022 年 4 月 28 日
回答済み: Chetan 2023 年 11 月 16 日
Report 1: Print organizations between certain years. Ask the user to input the value of a start year and end year and print all organization information along with its students between the start and end years. Save this data into file named report1.txt
Report 2: Print all students from a specific state. Ask the user to input the value of the state and print all students from all organizations who are from that state. Save this report into a file named report2.txt
Report 3: Print students based on organization affiliation and state. Ask the user to input the value of the organization’s affiliation and state. Print out all the students who match the input values. For example, print all students who are from TN in Social organizations. Save this report into file named report3.txt

回答 (1 件)

Chetan
Chetan 2023 年 11 月 16 日
I understand that you are trying to process the text data and generate report based on it
To generate the reports as per your requirements, we can use MATLAB's text file reading capabilities. Here's a brief outline of how you might approach this:
  1. Read the text file: Use `fopen` to open the file and `textscan` to read the data and parse relevant information.
  2. Generate Report 1: Ask the user for the start and end years. Filter the data based on these years and save the relevant organization information and students to 'report1.txt'.
  3. Generate Report 2: Ask the user for the state. Filter the data based on this state and save the relevant students to 'report2.txt'.
  4. Generate Report 3: Ask the user for the organization’s affiliation and state. Filter the data based on these inputs and save the relevant students to 'report3.txt'.
Here's some sample code that might help you get started:
% Open the file
fid = fopen('data.txt', 'r');
% Read the data
data = textscan(fid, '%s', 'Delimiter', '\n');
% Close the file
fclose(fid);
% Parse the data
% ... (You will need to write this part based on the specific format of your data)
% Generate Report 1
startYear = input('Enter start year: ');
endYear = input('Enter end year: ');
% Filter the data based on the years and save to 'report1.txt'
% ...
% Generate Report 2
state = input('Enter state: ');
% Filter the data based on the state and save to 'report2.txt'
% ...
% Generate Report 3
affiliation = input('Enter organization’s affiliation: ');
state = input('Enter state: ');
% Filter the data based on the affiliation and state and save to 'report3.txt'
% ...
Refer to following MathWorks Documentation for detailed usage of these functions:
Hope it helps !

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by