excel data into a single columns using loop
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Does anyone know how to make this data into a single columns with spacing interval using for loop? from top data to bottom data

.

댓글 수: 2
Hi stephen, the answer provided by the link doesnt help. maybe you can help me?
채택된 답변
ANKUR KUMAR
2018년 9월 30일
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
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
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]
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
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.
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
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')
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
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]?
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.
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.
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에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
