Averaging over specific columns in a for loop not working

CompanyTable = cell(nCompany,4);
for n = 1:nCompany
%determine and display the name of the company studied
thisCompany = uniqNames{n};
fprintf('\nStudying %s \n',thisCompany);
tf = strcmp(row1,thisCompany);
thoseCompany = cell2mat(CompanyData(tf,3));
tmp = movmean(CompanyData,nCompany,1);
Averagelate = tmp(:,nCompany:nCompany:end);
%latetime = [shipData{2:end,thisCompany}
Currently I am looking to average out companies data based off certain times. I saw a thread about using movmean and I have attempted that, but I am currently getting "Invalid data type. First input must be numeric or logical." CompanyData is an array of only nunmeric values.

4 comentarios

Rik
Rik el 19 de Mzo. de 2020
Where did you define this variable? The line above it suggests it is not a numeric array, but a cell array instead.
The variable is defined above:
%Read Data
shipData = readcell('MP_JIT_data.xlsx');
CompanyData = shipData(2:end,2:end);
CompanyData is only numeric values and is what I am using to calculate the averages. CompanyTable is an empty cell array to store later values.
Rik
Rik el 19 de Mzo. de 2020
What does class(CompanyData) return?
Taylor Sumlin
Taylor Sumlin el 19 de Mzo. de 2020
Editada: Rik el 20 de Mzo. de 2020
CompanyData =
365×8 cell array
{[45]} {[ 0]} {[12]} {[24]} {[ 0]} {[12]} {[ 0]} {[ 6]}
{[ 0]} {[21]} {[22]} {[ 0]} {[21]} {[22]} {[19]} {[11]}
{[29]} {[23]} {[21]} {[27]} {[23]} {[21]} {[ 0]} {[ 6]}
{[ 5]} {[ 0]} {[ 4]} {[ 5]} {[ 0]} {[ 4]} {[ 0]} {[ 7]}
{[ 1]} {[33]} {[52]} {[ 1]} {[33]} {[52]} {[ 6]} {[ 8]}
{[40]} {[ 3]} {[ 2]} {[ 5]} {[ 3]} {[ 2]} {[ 5]} {[ 7]}
{[ 5]} {[25]} {[ 4]} {[30]} {[25]} {[ 4]} {[16]} {[ 6]}
{[ 5]} {[19]} {[13]} {[ 5]} {[19]} {[13]} {[25]} {[ 4]}
{[ 2]} {[ 0]} {[ 4]} {[ 2]} {[ 0]} {[ 4]} {[ 2]} {[10]}
{[ 6]} {[21]} {[ 3]} {[ 6]} {[21]} {[ 3]} {[ 0]} {[10]}
...[cropped to only a few lines for readability]
Ah it literally says cell array. I missed that entirely. I am quite new to MATLAB

Respuestas (1)

Rik
Rik el 20 de Mzo. de 2020
Editada: Rik el 20 de Mzo. de 2020
You can use cell2mat to convert the cell to a double array. Then it will work with movmean.

La pregunta está cerrada.

Productos

Etiquetas

Preguntada:

el 19 de Mzo. de 2020

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by