How to add serial number and some other constant values to my output?

10 ビュー (過去 30 日間)
raghavendra kandukuri
raghavendra kandukuri 2018 年 9 月 14 日
回答済み: ANKUR KUMAR 2018 年 9 月 14 日
I have an output as Text file, which has 9 outputs or 9 columns of data, i want to add serial number or step number for every entry starting from 1 and i want my Torque Field to be '-1' for all the rows and Acquistionrate_HZ to be '10' for all the rows.
Note: number of rows differ every time based on input, PFA output/notepad file

回答 (1 件)

ANKUR KUMAR
ANKUR KUMAR 2018 年 9 月 14 日
You can simple add a column at the front of your matrix and use dlmcell to write in a text file.
Suppose A is you cell matrix which contains the data which is in your .txt file.
A={'a','b','c','d','e';'f','g','h','i','j';'k','l','m','n','o';'p','q','r','s','t'}
A =
4×5 cell array
'a' 'b' 'c' 'd' 'e'
'f' 'g' 'h' 'i' 'j'
'k' 'l' 'm' 'n' 'o'
'p' 'q' 'r' 's' 't'
A=[arrayfun(@(x) num2str(x) ,[-1,1:size(A,1)-1] ,'uni',0)' A]
A =
4×6 cell array
'-1' 'a' 'b' 'c' 'd' 'e'
'1' 'f' 'g' 'h' 'i' 'j'
'2' 'k' 'l' 'm' 'n' 'o'
'3' 'p' 'q' 'r' 's' 't'

カテゴリ

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by