Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read data in excel by matlab

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how matlab reads data in excel", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how matlab reads data in excel" this article bar.

Question Background: There are two tables of the list of personnel in the department, one of which is the list of all personnel in the department (there are three people in the list of participants who are not listed in the general list).

A list of people who participated in a certain training, not everyone in the department participated in this training

(I am one of those who did not participate.) So now we have to sift through these two forms to find a list of people who didn't participate.

Method 1: Look with your eyes.

You're exhausted,(although there are only over 100 people, it's enough to torture you)

Method 2: I don't know how to use Excel built-in functions, it may be more troublesome to put

Method 3: Use programming language to achieve,(I only know matlab)

Idea 1: import two Excel name data stored in two cells respectively, with two layers of loop traverse it two, compare each element, if the same, put the total list of that element blank

。(The outer layer is the general list, and the inner layer is the list of people participating in the training)

Idea 2: Import the data of two names in Excel and merge them into one piece, and then use a good way to duplicate the array I talked about before (similar to, cannot copy, slightly change), and the rest is not the list of people who did not participate.

There is a BUG: two names are exactly the same, then go to compare the student number

Before programming, I need to talk about how matlab reads data in excel.

The xlsread function helps us read Excel.

Here's a simple usage

[num , txt , raw] = xlsread(filename)

Note:

num is the numeric part of the specified excel

txt is the portion of text in the specified excel, txt is a cell

raw numeric text in a block, raw is a cell

If you don't want it, use ~ to replace it. It's fine if you don't need ~. Anyway, you don't need it. It doesn't matter if you leave it there.

filename is the filename (with extension) of the specified excel file

The rest of the usage readers help themselves,

, input parameters can also bring the scope in excel,

How many sheets, etc

Code of Idea 1:

clear

clc

[num_list,name_list]=xlsread ('name_list.xlsx');% import total list

[num_practice,name_practice]=xlsread ('practice_list.xlsx');% Import a list of participants

for i=1:length(name_list)% Traverse the total list

name1=name_list{i};

for j=1:length(name_practice)% Traverse the training list

name2=name_practice{j};

if strcmpi(name1,name2)==1% See if the names in the training list appear in the total list

name_list{i}=[];% If present, leave this element in the master list blank

% You can't use parentheses here. Using parentheses at the end of each outer loop may reduce the name_list by one dimension.

% Then there may be cases where the index extracts the dimensions of the matrix

% with small brackets, directly delete a small cell in the big cell

% in curly brackets, is to set the element in the small cell in the large cell to empty, the small cell still exists

break

end

end

end

Do you remember cellfun? If you don't remember, turn to the previous article (just click on this sentence directly

disp(name_list(~cellfun('isempty', name_list)))

Result: One second after running the code

Code of Idea 2:

clear

clc

[num_list,name_list]=xlsread ('name_list.xlsx');% import total list

[num_practice,name_practice]=xlsread ('practice_list.xlsx');% Import a list of participants

WholeName = [name_list;name_practice];% Merge two lists

% Below de-emphasize names in WholeName

names = {};

cnt = 0;

% The idea is that two lists must have duplicate names when stacked together;

% has duplicate names so there must be two or more elements in ind below me, leave them empty;

% If it is a non-heavy element, save it separately and then set it empty;

% Because three names not in the total list were added to the training list at the end.

% So this method will have three more people than the previous method,

% However, this does not affect, it is a problem of data entry

while ~isempty(WholeName)

ind = find(strcmp(WholeName{1},WholeName) == 1);

if length(ind) >= 2

WholeName(ind) = [];

else

cnt = cnt + 1;

names{cnt} = WholeName{1};

WholeName(1) = [];

end

end

disp(names')

Result: One second after running the code

The second method is to write and remember.

And remember what you learned before.

The above is "matlab how to read excel data" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report