필터 지우기
필터 지우기

Adding semicolon into data

조회 수: 9 (최근 30일)
Lucas Stadnik
Lucas Stadnik 2019년 10월 31일
답변: Lucas Stadnik 2019년 10월 31일
Hi guys, I'm using Matlab 2014b (I don't have access to a better version) and I have a set of data like this:
A=x1,x2,x3,x4,x5,x6,...,xn
I need to add a semicolon for every pair, so I get sth like this:
A=x1,x2;x3,x4;...;xn-1,xn
How can I do that?
I created A using dlmwrite, but when I try to use delimeter in this function I get the following error:
"Delimeter is not a valid attribute or delimiter. Delimiter must be a single character"
Can anybody help?
I don't have access to writematrix function.
  댓글 수: 2
the cyclist
the cyclist 2019년 10월 31일
I'm confused.
When you say you have "a set of data" ... what exactly do mean? Is A a MATLAB (numeric) row vector?
Are you trying to write that vector to a file? With some semicolons?
Also, is it possible that part of the problem is that you misspelled the word "delimiter", which is why MATLAB couldn't interpret it?
Lucas Stadnik
Lucas Stadnik 2019년 10월 31일
편집: Lucas Stadnik 2019년 10월 31일
I had two vectors:
x=(x1,x2,x3,...,xn)
y=(y1,y2,y3,...,yn)
Then,
z=[x(:),y(:)] ';
dlmwrite('z.txt',z)
This what I've done so far and I get this the txt file like this:
z=(x1,y1,x2,y2,y3,...,xn,yn);
Actually, it worked, but the semicolon is added for every single point, not for every pair
dlmwrite('z.txt',z,'delimeter',';')

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

채택된 답변

Lucas Stadnik
Lucas Stadnik 2019년 10월 31일
From another post:
Try this low-level code:
-----------------------------------------
x = randi(9,[1,2*6001]); % ACTUAL DATA
fileID = fopen('data.txt','w');
for k = 1:2:numel(x)-1
fprintf(fileID,'%g,%g;',x(k),x(k+1));
end
fclose(fileID);
-----------------------------------------
Enjoy!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by