필터 지우기
필터 지우기

How can I sort data from an excel file and assign ID's to binary classes?

조회 수: 1 (최근 30일)
Michael Seed
Michael Seed 2021년 9월 16일
댓글: KSSV 2021년 9월 16일
num1 = xlsread('Smart_meter_data.xlsx', 'B2:AW93');
data = num1;
num2 = xlsread('Smart_meter_data.xlsx', 'AX2:AX93');
id = num2;
I have an excel file that is 92 rows of 48 columns of measured values, and the 49th column are the ID numbers for what is being measured in each row. How do I write an 'if statement' to see if each row contains measurements above a certain value, and if it does then the corresponding ID number in the last column is true? Logically I'm trying to do something like this, but this obviously isn't a working syntax.
if (data > 2)
id = yes
elseif (id~=yes)
id = no
end

답변 (1개)

KSSV
KSSV 2021년 9월 16일
편집: KSSV 2021년 9월 16일
You need not to use a loop. You can go by inequalities, where you will get logical indices as output. The logical indices have 1 where condition is true and 0 where condition is false. You can convert the logical to double using the function double.
id = data > 2 ;
  댓글 수: 7
Stephen23
Stephen23 2021년 9월 16일
@KSSV: this line, which is not valid MATLAB syntax:
if id = data > 2;
@Michael Seed: forget about IF, use logical indexing and FPRINTF.
KSSV
KSSV 2021년 9월 16일
Check the class of data. It might be a string. Use readtable to load excel file data.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by