How can i reformat matriks from one column to one row

조회 수: 1 (최근 30일)
Retno Purwaningsih
Retno Purwaningsih 2021년 8월 16일
댓글: Retno Purwaningsih 2021년 8월 18일
I have data like this in many file
File 222
222 -10.894943 127.960434 0.0136
222 -10.994533 127.997716 0.0163
File 223
223 -10.944739 127.979071 0.0272
223 -11.044324 128.016368 0.0217
223 -11.143902 128.053696 0.0448
From that data i want to be like this
File 222
222 -10.894943 127.960434 0.0136 0.0163
File 223
223 -10.944739 127.979071 0.0272 0.0217 0.0448
I just want the first row and the next column is the value of column 4 so on, the corresponding row (except first row) need to be eliminated.
First i define each column, and than transpose column 4 but it doesn't work
clc;
clear;
format short;
f =dir('D:\MATLAB\table_*.txt');
for A=1:length(f);
D=f(A).name;
ff=D(:,7:9)
data=load(D);
ref=data(:,1);
lat=data(:,2);
lon=data(:,3);
data1=data(:,4);
tr=data1'
row1=data(,:1);
col1=row1(:,1);
col2=row1(:,2);
col3=row1(:,3);
final=[col1 col2 col3 tr]
%save file
file_name = sprintf('Table_' ff 'fix.txt');
dlmwrite(file_name,final,'delimiter','\t','precision',10);
end

채택된 답변

DGM
DGM 2021년 8월 16일
편집: DGM 2021년 8월 16일
Something like this?
A = randi([10 99],3,4) % example array
A = 3×4
84 81 48 69 92 97 23 40 96 57 29 60
v = [A(1,1:end-1) A(:,end).']
v = 1×6
84 81 48 69 40 60
Either way, this is going to give you an error:
row1=data(,:1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 PID Controller Tuning에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by