Error using ' (line 214) Undefined function 'ctranspose' for input arguments of type 'table'. Use the ROWS2VARS function instead.

9 Ansichten (letzte 30 Tage)
when running my code i get a odd error: Error using ' (line 214) Undefined function 'ctranspose' for input arguments of type 'table'. Use the ROWS2VARS function instead. I don't use the ctranspose function and also don't have line 214 can someone help me. My code is below, hope someone can help me
clear;
clc;
format long
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readtable('FFDATA.csv')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sets Priors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
multipleSR=1.27;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Defines models
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MktRF_star = data(:,2);
SMB_star = data(:,3);
HML_star = data(:,4);
RMW_star = data(:,5);
CMA_star = data(:,6);
MktRF = data(:,7);
SMB = data(:,8);
HML = data(:,9);
RMW = data(:,10);
CMA = data(:,11);
K=10;
F = [MktRF_star SMB_star HML_star RMW_star CMA_star MktRF SMB HML RMW CMA];
Flabel = ['Mkt_'; 'HML_'; 'SMB_';'RMW_';'CMA_';'Mkt ';'HML ';'SMN ';'RMW ';'CMA '];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creates Models
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T=size(F,1);
T0=K+1; %Minimum number of observations needed to estimate the regression is K + 1
% Creates the models and their respective factors
Numbermodels=2^(K-1);
IdentityMatrix=eye(K-1);
model.Fbar{1} = MktRF_star;
model.SelMatrixF{1} = 1;
model.label{1} = Flabel(1,:);
model.size{1}=1;
model.sizeFtilda{1}=K-model.size{1};
Fexmkt=F(:,2:end);
model.Ftilda{1} = Fexmkt;
model.Fbarexmkt{1} = [];
Flabelexmkt=Flabel(2:end,:);
for j=2:Numbermodels
model.SelMatrixF{j} = find(dec2binvec(j-1,K-1)==1);
model.Fbarexmkt{j} = (IdentityMatrix(model.SelMatrixF{j},:)*Fexmkt')';
model.Fbar{j} = [mktrf (IdentityMatrix(model.SelMatrixF{j},:)*Fexmkt')'];
model.SelMatrixFtilda{j} = find(dec2binvec(j-1,K-1)==0);
model.Ftilda{j} = [(IdentityMatrix(model.SelMatrixFtilda{j},:)*Fexmkt')'];
model.label{j} = [Flabel(1,:); Flabelexmkt(model.SelMatrixF{j},:)];
model.size{j}=length(model.SelMatrixF{j})+1;
model.sizeFtilda{j}=K-model.size{j};
end
function out = dec2binvec(dec,n)
%DEC2BINVEC Convert decimal number to a binary vector.
% DEC2BINVEC(D) returns the binary representation of D as a binary
% vector. The least significant bit is represented by the first
% column. D must be a non-negative integer.
% DEC2BINVEC(D,N) produces a binary representation with at least
% N bits.
%
% Example:
% dec2binvec(23) returns [1 1 1 0 1]
%
% See also BINVEC2DEC, DEC2BIN.
%
% MP 11-11-98
% Copyright 1998-2003 The MathWorks, Inc.
% $Revision: 1.5.2.4 $ $Date: 2003/08/29 04:40:56 $
% Error if dec is not defined.
if nargin < 1
error('daq:dec2binvec:argcheck', 'D must be defined. Type ''daqhelp dec2binvec'' for more information.');
end
% Error if D is not a double.
if ~isa(dec, 'double')
error('daq:dec2binvec:argcheck', 'D must be a double.');
end
% Error if a negative number is passed in.
if (dec < 0)
error('daq:dec2binvec:argcheck', 'D must be a positive integer.');
end
% Convert the decimal number to a binary string.
switch nargin
case 1
out = dec2bin(dec);
case 2
out = dec2bin(dec,n);
end
% Convert the binary string, '1011', to a binvec, [1 1 0 1].
out = logical(str2num([fliplr(out);blanks(length(out))]')');
end

Akzeptierte Antwort

Steven Lord
Steven Lord am 29 Apr. 2021
Your variable data, being created by readtable, is a table. So are the variables like MktRF_star that you create by extracting one of the variables from that table. So is the variable F you create from those variables and so is the variable Fexmkt that you create from F.
Inside your last loop you have this line of code (commented out so I can execute a line of code later in this answer.)
% model.Fbarexmkt{j} = (IdentityMatrix(model.SelMatrixF{j},:)*Fexmkt')';
Not only does that try to transpose the table Fexmkt (which won't work) but it also tries to multiply something by that table (which also wouldn't work.)
If you want to access the data inside a table array, you can use curly braces.
load patients
P = table(Age, Systolic, Diastolic);
head(P)
ans = 8×3 table
Age Systolic Diastolic ___ ________ _________ 38 124 93 43 109 77 38 125 83 40 117 75 49 122 80 46 121 70 33 130 88 40 115 82
smallerTable = P(1:5, :)
smallerTable = 5×3 table
Age Systolic Diastolic ___ ________ _________ 38 124 93 43 109 77 38 125 83 40 117 75 49 122 80
matrixOfData = P{1:5, :}
matrixOfData = 5×3
38 124 93 43 109 77 38 125 83 40 117 75 49 122 80
whos P smallerTable matrixOfData
Name Size Bytes Class Attributes P 100x3 3831 table matrixOfData 5x3 120 double smallerTable 5x3 1551 table
See this documentation page for more information about accessing data in a table array.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by