필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Write a 1D matrix to a text file such that only 6 numbers printed in each line

조회 수: 1 (최근 30일)
H R
H R 2015년 9월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello all, I have a long 1D matrix A for example say: A=A[1,2,3,4,5,6,...,21]; I want to write this matrix in to a tab delimited text file in such a way that not more than 6 numbers is printed in each line in the text file:
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21
Could you please help on how to do that in matlab? Thank you.

답변 (1개)

Star Strider
Star Strider 2015년 9월 23일
There are probably different ways to do this, but this works:
A = 1:21; % Original Data
A1 = {reshape(A(1:6*fix(length(A)/6)), [], 6); A(6*fix(length(A)/6)+1:end)}; % Create Cell Array
filename = 'NewFile.csv';
dlmwrite(filename, A1{1})
dlmwrite(filename, A1{2}, '-append')
type(filename) % Proof!
1,4,7,10,13,16
2,5,8,11,14,17
3,6,9,12,15,18
19,20,21

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by