Hello all
The code below overwrites the previous values in the column Delay and inserts only the last ones (20). There should be a way to append the array instead of overwriting it but I dont know how. Any help will be appreciated
if contains(baseFileName,"A01")
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
bigtable(:,'Delay') = {10}
elseif contains(baseFileName,"A02")
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
bigtable(:,'Delay') = {20}
end

답변 (2개)

Cris LaPierre
Cris LaPierre 2021년 12월 7일

0 개 추천

If your tables have the same variable names (order does not matter), then just use square brackets.
newTable = readtable(fullFileName,opts)
bigtable = [bigtable;newTable];

댓글 수: 5

Ioannis Doumanis
Ioannis Doumanis 2021년 12월 7일
it does not work. The problem is that the values of the column delay are overwritten and not updated with the correct values. I want something like this:
when first condition is statisfied insert value 10 to column delay
When second condition is satisfiied insert value 20 to column Delay
At the moment the code simply inserts 20 in the column delay
Ioannis Doumanis
Ioannis Doumanis 2021년 12월 7일
편집: Ioannis Doumanis 2021년 12월 7일
I modified the code but it works partially. Matlab inserts 0s in the rows where It should enter 10 or 20
if contains(baseFileName,"A01")
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
bigtable(1:6000,'Delay') = {10};
elseif contains(baseFileName,"A02")
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
bigtable(6000:12000,'Delay') = {20};
elseif contains(baseFileName,"A03")
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
bigtable(12000:18000,'Delay') = {30};
I'm not sure I understand what your code is doing. Why do you assign the result of readtable to a cell array, but them vertically concatenate x?
The assignment to specific rows of a variable in a table is easy enough to do
bigtable.Delay(1:6000) = 10;
Ioannis Doumanis
Ioannis Doumanis 2021년 12월 8일
I am reading a specific data sample (300 samples) from several csv files. I want the samples the one after the other. I tried bigtable.Delay(1:6000) = 10; and still does not work. The table is filled with 0s instead of 10s and 20s. Currently I get correctly only the result (30) of the last condition of sth switch statement.
Cris LaPierre
Cris LaPierre 2021년 12월 20일
Consider sharing your data files. You can attach them using the paperclip icon.

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

Ioannis Doumanis
Ioannis Doumanis 2021년 12월 8일

0 개 추천

I also tried this. I still get 0s for the first two conditions. I am not sure why
delayvalues = [delayvalues; delay];
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
% add column at the end of the table
switch true
case (contains(baseFileName,"A01"))
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
delay = 10;
bigtable(1:6000,'Delay') = delayvalues(1);
case (contains(baseFileName,"A02"))
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
delay = 20;
bigtable(6000:12000,'Delay') = delayvalues(2);
case (contains(baseFileName,"A03"))
x{k} = readtable(fullFileName,opts)
bigtable = vertcat(x{:})
delay = 30;
bigtable(12000:18000,'Delay') = delayvalues(3);
otherwise
% do nothing
end

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2021년 12월 7일

댓글:

2021년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by