Error in my function

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 个评论

  • Where is the problem? My Data has the class "table"
Is it possible to convert it to string?
Then i get this error: Error using string Conversion to string from table is not possible.
Can you attach header_out?
This code expects header_out to be a cell. A table has a completely different data structure. Did you write this code yourself or was this given to you? A good function should document what syntax it expects. That way you have a description of what kind of data should be in header_out.
A friend has given the code to me. I'll ask my colleague
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 个)

类别

帮助中心File Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by