read specific data from excel and create a vector ?

I have attached excel file
and to create a row vector 1*24 like
A1=[0 0 0 0 2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 2.2 0 0 0 0 0 0 0 0 0];
A2=[0 0 0 0 0 0 0 0 0 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 0 0 0 0];

 채택된 답변

KSSV
KSSV 2017년 7월 31일
편집: KSSV 2017년 7월 31일
[num,txt,raw] = xlsread('app.xls') ;
A1 = zeros(1,24) ;
A1(num(1,2):num(1,3)) = num(1,1) ;
A2 = zeros(1,24) ;
A2(num(2,2):num(2,3)) = num(2,1) ;

댓글 수: 2

The
clc; clear al ;
do not appear to be doing any useful work there ?
MUKESH KUMAR
MUKESH KUMAR 2017년 7월 31일
편집: MUKESH KUMAR 2017년 7월 31일
thanks for solution if we have more than two rows like for 10 rows in excel then how can we use 'for loop' for it? I tried this A1 is B1{1} and A2 is B1{2} for two rows: [num,txt,raw] = xlsread('app.xls') ; for u = 1:2 for v = 1:2; B1{u}=zeros(1,24); B1{u}(num(v,2):num(v,3))= num(v,1); end end

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 7월 31일
(This code is not tested)
[num, txt] = xlsread('app.xls');
nrow = size(num, 1);
use_cell = cell(nrow, 2);
for K = 1 : nrow
this_entry = zeros(1,24);
this_entry( num(K,2) : num(K,3)) = num(K,1);
use_cell{K,1} = txt{K,1};
use_cell{K,2} = this_entry;
end
use_struct = cell2struct(use_cell(:,1), use_cell(:,2));
Now there will be use_struct.a1 and use_struct.a2

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

질문:

2017년 7월 31일

편집:

2017년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by