Why is my table displaying 1x1 in workspace but displays actual values in command window?

21 views (last 30 days)
So I am trying to convert monthly data into quartely and this is my code (below). However, whenever I run the code below, in the output (command window), I get:
months TB
Percent
___________ _______
01-Jan-1961 3.04
01-Feb-1961 3.11
01-Mar-1961 3.21
01-Apr-1961 3.28
01-May-1961 3.14
...
which is what I am looking for but in the workspace table, it shows:
Therefore, when I run the retime function, it shows this error:
Error using timetable/retime
All variables in input timetables must be numeric, datetime, or duration when synchronizing using 'mean'.
Error in econ_406_Assignment_1 (line 22)
tt= retime(TBm, 'quarterly', 'mean');
Any help would be appreciated!
%% 2- Converting TB, CPI and CPIX data from monthly to quarterly.
quarters = datetime([1961,01,01],'Format','yyyy/MM/dd'):calquarters(1):datetime([2022,06,30]);
months = datetime(1961,01,01):calmonths(1):datetime(2022,06,30);
months = months';
a = readtable("B-Table-1010012201-eng.csv", 'Range', 'A12:B750');
TB = a(1:end,2);
TBm = timetable(months,TB)
tt= retime(TBm, 'quarterly', 'mean');

Answers (2)

Steven Lord
Steven Lord on 18 Sep 2022
You're creating a timetable whose elements are tables. If you want to change a table into a timetable instead take a look at the table2timetable function.

dpb
dpb on 18 Sep 2022
months = (datetime(1961,01,01):calmonths(1):datetime(2022,06,30)).';
a = table(randn(size(months)));
TB = a(1:end,1);
whos months a TB
The above simulates what your code to the point of creating TB does -- your a variable is a table and, ergo, so is TB.
Somehow you ended up creating a table that is a cell array of tables as the data variable; your code doesn't precisely show doing that but that's what the workspace shows it does contain.
Do something more like
months = (datetime(1961,01,01):calmonths(1):datetime(2022,06,30)).';
a=readmatrix("B-Table-1010012201-eng.csv");
ttTB=timetable(months,a(:,2); % create a timetable
ttTBQ=retime(ttTB, 'quarterly', 'mean');
If the above fails, attach your data file so folks have something specific to utilize for testing code...

Categories

Find more on Tables 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!