I have 4 different dimension matrices(A:1100X1, B:2200X1,C: 3300X1,D:3300X1)..I want to keep all 4 in one matrix..

Hi, I have 4 different dimension matrices(A:1100X1, B:2200X1,C: 3300X1,D:3300X1)..I want to keep all 4 in one matrix..
the code written as
clc
clear all
format compact
warning off
L = []; indexgood=1;
%mrsgarch_n
load mrsgarch_n
eval(['L(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
% MRSGARCH-t2
load mrsgarch_t2
eval(['L(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
% MRSGARCH-GED
load mrsgarch_g
eval(['L(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
% MRSGARCH-t1
load mrsgarch_t
eval(['L(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
cd junk\VF
save loglik.txt L -ascii -double -tabs
cd ..
cd ..
when I run this code.. the following error msg is coming..
??? Subscripted assignment dimension mismatch.
Error in ==> ooslikelihoods at 18 eval(['L(:,',num2str(indexgood),') = Loglike(:);']);
Thanks
Kishore

3 Comments

What are you trying to do? Your code looks awkward. How does your code relate to the question in your title?
Thanks Jiang for the comment..
I am new to Matlab, I have downloaded a program prepared by Juri Marcucci and trying to replicate the tables presented in his paper "Forecasting Stock Market Volatility with Regime-Switching GARCH Models".
When run the program for insample, it stored likelihood ratios of 4 different distributions in the form of mrcgarch_n.mat, mrsgarch_t.mat, mrsgarch_t2.mat and mrsgarch_g.mat, all have different rowsX1 matrices.
the current file to is get the loglikelihoods for the out of sample evaluations for that I need to get all the log-likelihoods into one matrix.
The above program is written by him, the program is running and storing the all the likelihoods when I give different names to L..
load mrsgarch_n
eval(['L(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
% MRSGARCH-t2
load mrsgarch_t2
eval(['L1(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
% MRSGARCH-GED
load mrsgarch_g
eval(['L2(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
% MRSGARCH-t1
load mrsgarch_t
eval(['L3(:,',num2str(indexgood),') = Loglike(:);']);
indexgood=indexgood+1;
Thanks
That's either a good example of bad programming, or else code written for MATLAB 4 or earlier.

Sign in to comment.

 Accepted Answer

I assume each of your data file contains the same variable Loglike, but the size is different from file to file, first is 1100x1, second is 2200x1, etc. You want to combine them.
Try this:
L = [];
load mrsgarch_n
L=[L;Loglike];
load mrsgarch_t2
L=[L;Loglike];
load mrsgarch_g
L=[L;Loglike];
load mrsgarch_t
L=[L;Loglike];

More Answers (1)

First, please read:
Beyond that: it is not possible in MATLAB to have numeric arrays that have different column sizes. If you want to use save() specifically to create four columns of data of different sizes that load() would load in, then you cannot do that. There are other ways that it would be possible to get the data written out in to columns, but load() would not be able to handle the result.
Does your data need to be saved as text? If so, then what are the requirements imposed by what-ever program you plan to read it in with? It makes more sense to construct a solution that fits the needs of what you cannot change, then for us to suggest different things you might want to do.

2 Comments

Thanks Walter..Yes I want to save these results in a textfile and call it in another program.
Do you have control of how the other program reads the data? Or does it need a particular format? If it needs a particular format, what is that format? If it is expecting spaces to indicate that there are no more values in a column, then it is probably expecting each column to be a very specific width.
Is the other program able to treat NaN as indicating that there is no data?

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!