Error in my function

조회 수: 2 (최근 30일)
Mark S
Mark S 2020년 4월 3일
댓글: Walter Roberson 2020년 4월 4일
Hey, i wanna make a time vector of my data.
I have written this function:
function [ data_out_time ] = create_time( header_out , data_out_norm )
%% Create a time vector
% by reading the sampling interval of a measurement in the file
le= size(data_out_norm,1); % find out length of my cutted data matrix
% there may be a comma for decimal seperator
% -> search for it and replace it by a dot, otherwise the interval will be incorrect!
str_interval = strrep(header_out{1 , 1},',','.');
% convert sample time:
interval = str2double(str_interval); % from string to double
% Check if sample time is in range of t > 0
if interval<=0
error('incorrect sampling interval'); % Display error message in this case
end
%create output matrix
data_out_time = zeros(le,1); % prelocating matrix for performance
for r = 1:1:le % loop for generating time vector
data_out_time(r) = interval * (r-1); % time has to start at 0 -> *(r-1)
end
But i get everytime this error:
Brace indexing is not supported for variables of this type.
Error in create_time (line 9)
str_interval = strrep(header_out{1 , 1},',','.');
Where is the problem? My Data has the class "table"
  댓글 수: 6
Mark S
Mark S 2020년 4월 4일
A friend has given the code to me. I'll ask my colleague
Walter Roberson
Walter Roberson 2020년 4월 4일
If header_out were a table, then header_out{1,1} would be valid and would be the contents of the first row of the first column of the table
The code would also be valid if header_out were a cell array, or were a string array.
You would get that error message if header_out is character vector (including a file name), or numeric array, or is [] indicating empty.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by