"Improper assignment with rectangular empty matrix

Estimados, estoy realizando un análisis de cluster, y cuando corro el script me genera ese error al correr
for p=1:length(t2)
in(p)=find(t1==t2(p));%LINEA QUE GENERA EL ERROR
end
el cuerpo del script es el sgte:
%PARTE I
%Analisis de Cluster para obtener las conf sinopticas de viento cruzado
clear all
close all
cd /home/jacqueline/Documentos/Antartica/pre_proceso/Reanalisis_clusters
%Creando anomalias por metodo de cluster
load HGT500.mat %cargando la matriz de hgt (datos de reanalis)
REANALYSIS=HGT500;
clear HGT
%Cargando las fechas de los 5 fenomenos significativos
load Fecha_CW.mat
f=floor(Fecha_CW);
clear Fecha_CW
% get meteo data for 12 UTC
% WATCH OUT! be careful with how many attributes the meteo data has (lon,
% lat,level, time, etc)
REA_12Z=REANALYSIS(:,:,3:4:end); % (lon,lat,time) time 4 per day each 6h
% new time for meteo data
t_12z=floor(t(3:4:end));%deja solamente el dia
m_12z=month(t_12z);
% seasonal points for Reanalysis data, we want to get the climatology of
% each season during the last 10,5 years
% mr: monthly reanalysis
% s:summer, a:autumn, w:winter, p: springs
mr_s=[find(m_12z==12) find(m_12z==1) find(m_12z==2) ];
mr_a=[find(m_12z==3) find(m_12z==4) find(m_12z==5) ];
mr_w=[find(m_12z==6) find(m_12z==7) find(m_12z==8) ];
mr_p=[find(m_12z==9) find(m_12z==10) find(m_12z==11)];
% get seasonal variable and climatology
% Same but for events, we want to get the reanalysis data for all events
% and after that the anomalies (events - climatology)
% same but till 30 jun 2014
%f=f(f<=datenum(2014,06,30));
m_f=month(f);%FECHA DE MIS EVENTOS
% me: monthly events,
% s:summer, a:autumn, w:winter, p: springs
% e: events
me_s=[find(m_f==12)' find(m_f==1)' find(m_f==2)' ];%verano
me_a=[find(m_f==3)' find(m_f==4)' find(m_f==5)' ];%otono
me_w=[find(m_f==6)' find(m_f==7)' find(m_f==8)' ];%invierno
me_p=[find(m_f==9)' find(m_f==10)' find(m_f==11)'];%primavera
season=['s' 'a' 'w' 'p'];
%clear i p y
%eval:evaluar
for i=1:length(season)
% getting mean climatology
eval(['r_meanH_' season(i) '=nanmean(REA_12Z(:,:,mr_' season(i) '),3);']);
% getting seasonal reanalysis data
eval(['rH_' season(i) '=REA_12Z(:,:,mr_' season(i) ');']);
% getting seasonal reanalysis time
eval(['t_12z_' season(i) '=t_12z(mr_' season(i) ');']);
eval(['t1=t_12z_' season(i) ';']);
% tt: seasonal events time
eval(['tt_' season(i) '=f(me_' season(i) ');']);%me:eventos por estacion
eval(['t2=tt_' season(i) ';']);
% getting position of the events into reanalysis data time
%clear in
for p=1:length(t2)
in(p)=find(t1==t2(p));%LINEA QUE GENERA EL ERROR
end
% getting seasonal events in Reanalysis data
eval(['r_e_' season(i) '= rH_' season(i) '(:,:,in);']);
% getting anomalies
for y=1:length(t2) % length of t2 and hgt_e_season are equal
eval(['r_anomH_' season(i) '(:,:,y)= r_e_' season(i) '(:,:,y)-r_meanH_' season(i) ';']);
end
end
%las fechas de eventos+reanalisis son tt_a;tt_p;tt_s y tt_w (corrspondiente %a primavera, otono, invierno y verano)
lo mas curioso es que lo habia corrido antes con otros archivos de entrada y no tuve problemas.
Saludos

回答(1 个)

Stephen23
Stephen23 2015-5-18
编辑:Stephen23 2015-5-19
The answer is simple: the values of t1, t2, and p do not have one unique match that satisfies t1==t2(p), which means that find(t1==t2(p)) is non-scalar, which means that trying to allocate a non-scalar array to a scalar position... gives an error.
Unless you can change the code so that there is one and only one value of t1 that equals t2(p), then this will always be an error.
All of the eval calls are not-beautiful... you should learn to avoid using eval everywhere in your code. It is not good programming practice to generate variables names dynamically: this is poor practice as has been explained many times on this forum, and is not recommended by MATLAB themselves:
When you use eval for basic functionality like this you miss out on lots of useful tools such as code hinting, error highlighting, highlighting variables, help shortcuts, and much more. Do not use eval for basic MATLAB functionality. Instead learn to use indexing and the different data types.
To know more about why, read this thread:

类别

Community Treasure Hunt

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

Start Hunting!

Translated by