excel data into a single columns using loop

Does anyone know how to make this data into a single columns with spacing interval using for loop? from top data to bottom data
.

 채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2018년 9월 30일

2 개 추천

What do you mean by equal spacing between each column. You cannot keep blank any element in matrix. You can do in cell. Here is an example.

A=xlsread('example.xlsx')
reshape(A,[],1) %if you want without keeping blank between each column
B=arrayfun(@(x) num2str(x) , A,'uni',0);
C=[B';{'','','';'','',''}];
reshape(C,[],1)

댓글 수: 12

LIM JIAXIN
LIM JIAXIN 2018년 9월 30일
편집: LIM JIAXIN 2018년 9월 30일
Is it possible to have blank space between them? and why is the result different from the command window compare to when i write it into the excel sheet?
ANKUR KUMAR
ANKUR KUMAR 2018년 9월 30일
편집: ANKUR KUMAR 2018년 9월 30일
yes, its possible. Just put them in cell. Output of
reshape(C,[],1)
is
ans =
15×1 cell array
'19'
'18'
'17'
''
''
'19'
'18'
'17'
''
''
'19'
'18'
'17'
''
''
The same is shown in excel too after writing in excel. xlswrite('example.xlsx',reshape(C,[],1),'sheet2','A1')
The output of above command is [see the attached image]
LIM JIAXIN
LIM JIAXIN 2018년 9월 30일
It's working! thank you but how do you make the value be 19 19 19, 18 18 18, 17 17 17 instead of 19 18 17
ANKUR KUMAR
ANKUR KUMAR 2018년 9월 30일
편집: ANKUR KUMAR 2018년 9월 30일
Just remove transpose in this line
C=[B;{'','','';'','',''}];
Previously, there was B' , but if you want in this fashion [19 19 19, 18 18 18, 17 17 17], then remove transpose.
LIM JIAXIN
LIM JIAXIN 2018년 9월 30일
Thank you!
Final question, let says if there is a row of value [10, 20, 30] at range A1:C1 is added to make the output become [10 19 19 19, 20 18 18 18,30 17 17 17]. however the value of [19 19 19,18 18 18,17 17 17] starts at A3:C5 assuming there is random values in A2:C2. How do i write the code that is able to add the value from A1:C1 to produce the output?
ANKUR KUMAR
ANKUR KUMAR 2018년 9월 30일
편집: ANKUR KUMAR 2018년 9월 30일
You can pass cell number as the argument, where you wish to start.
xlswrite('file.xlsx',C,'sheet1','A1')
LIM JIAXIN
LIM JIAXIN 2018년 9월 30일
Maybe you got my intention wrongly. What I meant was that for the previous example, now there is a additional 2 rows of value. So instead of having all the values coming out as the output, I wish to omit row 2. So in turn by combining the values of row 1 and row 3 onwards to give me a output of [10 19 19 19, 20 18 18 18,30 17 17 17] where the value of [10 20 30] comes from row 1 and [19 19 19,18 18 18,17 17 17] comes from row 3 onwards.
Firstly make a matrix or cell in matlab itself what you wish to see in excel file.
>> A=xlsread('example.xlsx')
A =
19 18 17
19 18 17
19 18 17
>> AA=[[10 20 30];A]
AA =
10 20 30
19 18 17
19 18 17
19 18 17
LIM JIAXIN
LIM JIAXIN 2018년 9월 30일
That doesn’t work as the values are all from the excel files. Is there a way to do it without manually typing in the value like AA=[[10 20 30]; A]?
ANKUR KUMAR
ANKUR KUMAR 2018년 9월 30일
Yes surely. MATLAB can do everything what one can think of. Anyways, please attach the excel file and clearly mention your desired output. We will surely help you.
LIM JIAXIN
LIM JIAXIN 2018년 10월 1일
 https://www.dropbox.com/s/ee9sfwk6z15ntkk/example.xlsx?dl=0 the excel file is inside the link as i reached the limit of uploading files right now. So my input is under sheet 1 and the desired output can be seen from sheet 2.
ANKUR KUMAR
ANKUR KUMAR 2018년 10월 1일
A=xlsread('example.xlsx')
A(2,:)=[];
reshape(A,[],1) %if you want without keeping blank between each column
B=arrayfun(@(x) num2str(x) , A,'uni',0)
C=[B;{'','','';'','',''}];
reshape(C,[],1)

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

추가 답변 (0개)

카테고리

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

태그

질문:

2018년 9월 30일

댓글:

2018년 10월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by