Effacer les filtres
Effacer les filtres

Why do I receive the error "Insufficient number of outputs from right hand side of equal sign to satisfy assignment. Error in A01_pr_rain_UK (line 3) fname=fns1.name "?

5 vues (au cours des 30 derniers jours)
close all;clear all;clc;
%
fns1=dir('Aus pr_Amon_ACCESS-CM2_ssp126_r1i1p1f1_gn_20150616-20990916_v20191108.nc'); %%%%%Australia
fns2=dir('Ger pr_Amon_AWI-CM-1-1-MR_ssp126_r1i1p1f1_gn_20150616-20990916_v20190529.nc'); %%%%%Germany
fns3=dir('pr_Amon_CanESM5-CanOE_ssp126_r1i1p2f1_gn_20150616-21000916_v20190429.nc'); %%%%%Canada
fns4=dir('pr_Amon_UKESM1-0-LL_ssp126_r1i1p1f2_gn_20150616-21000916_v20190503.nc'); %%%%%UK
fns5=dir('Ind pr_Amon_IITM-ESM_ssp126_r1i1p1f1_gn_20150616-20990916_v20201112.nc'); %%%%%India
fname1=fns1.name;
fname2=fns2.name;
fname3=fns3.name;
fname4=fns4.name;
fname5=fns5.name;
lon_aus=double(ncread(fname1,'lon'));
lat_aus=double(ncread(fname1,'lat'));
pr_aus=double(ncread(fname1,'pr'));
tm_aus=double(ncread(fname1,'time'));
pr_aus1=pr_aus*86400;
t_aus=datetime('1850-01-01')+tm_aus;
[yyyy_aus mm_aus dd_aus hh_aus mn_aus ss_aus]=datevec(t_aus);
lon_ger=double(ncread(fname2,'lon'));
lat_ger=double(ncread(fname2,'lat'));
pr_ger=double(ncread(fname2,'pr'));
tm_ger=double(ncread(fname2,'time'));
pr_ger1=pr_ger*86400;
t_ger=datetime('1850-01-01')+tm_ger;
[yyyy_ger mm_ger dd_ger hh_ger mn_ger ss_ger]=datevec(t_ger);
lon_can=double(ncread(fname3,'lon'));
lat_can=double(ncread(fname3,'lat'));
pr_can=double(ncread(fname3,'pr'));
tm_can=double(ncread(fname3,'time'));
pr_can1=pr_can*86400;
t_can=datetime('1850-01-01')+tm_can;
[yyyy_can mm_can dd_can hh_can mn_can ss_can]=datevec(t_can);
lon_uk=double(ncread(fname4,'lon'));
lat_uk=double(ncread(fname4,'lat'));
pr_uk=double(ncread(fname4,'pr'));
tm_uk=double(ncread(fname4,'time'));
pr_uk1=pr_uk*86400;
t_uk=datetime('1850-01-01')+tm_uk;
[yyyy_uk mm_uk dd_uk hh_uk mn_uk ss_uk]=datevec(t_uk);
lon_ind=double(ncread(fname5,'lon'));
lat_ind=double(ncread(fname5,'lat'));
pr_ind=double(ncread(fname5,'pr'));
tm_ind=double(ncread(fname5,'time'));
pr_ind1=pr_ind*86400;
t_ind=datetime('1850-01-01')+tm_ind;
[yyyy_ind mm_ind dd_ind hh_ind mn_ind ss_ind]=datevec(t_ind);
%%%%%%%%%%%%Australia model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pr_aus2=(pr_aus1((find(lon_aus>=70 & lon_aus<=75)),(find(lat_aus>=15 & lat_aus<=20)),(find(mm_aus==6))));
pr_aus_avg=squeeze(nanmean(nanmean(pr_aus2)));
%%%%%%%%%%%%IITM model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%Germany model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pr_ger2=(pr_ger1((find(lon_ger>=70 & lon_ger<=75)),(find(lat_ger>=15 & lat_ger<=20)),(find(mm_ger==6))));
pr_ger_avg=squeeze(nanmean(nanmean(pr_ger2)));
%%%%%%%%%%%%IITM model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%Canadar model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pr_can2=(pr_can1((find(lon_can>=70 & lon_can<=75)),(find(lat_can>=15 & lat_can<=20)),(find(mm_can==6))));
pr_can_avg=squeeze(nanmean(nanmean(pr_can2)));
%%%%%%%%%%%%IITM model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%Canadar model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pr_uk2=(pr_uk1((find(lon_uk>=70 & lon_uk<=75)),(find(lat_uk>=15 & lat_uk<=20)),(find(mm_uk==6))));
pr_uk_avg=squeeze(nanmean(nanmean(pr_uk2)));
%%%%%%%%%%%%IITM model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%IITM model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pr_ind2=(pr_ind1((find(lon_ind>=70 & lon_ind<=75)),(find(lat_ind>=15 & lat_ind<=20)),(find(mm_ind==6))));
pr_ind_avg=squeeze(nanmean(nanmean(pr_ind2)));
%%%%%%%%%%%%IITM model!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
plot(pr_aus_avg,'-k')
hold on;
plot(pr_ger_avg,'-r')
hold on;
plot(pr_can_avg,'-b')
hold on;
plot(pr_uk_avg,'-g')
hold on;
plot(pr_ind_avg,'-m')
legend ('Australia', 'Germany' ,'Canada', 'UK', 'India')
stop;
months=[ 'Jun'; 'Jul'; 'Aug'; 'Sep']
subplot(231)
pcolor(lon_aus,lat_aus,squeeze(pr_aus1(:,:,2))')
shading interp
caxis([0 30]);
axis([65 100 0 40])
hold on
load coast
plot(long,lat,'w','linewidth',2)
subplot(232)
pcolor(lon_ger,lat_ger,squeeze(pr_ger1(:,:,2))')
shading interp
caxis([0 30]);
axis([65 100 0 40])
hold on
load coast
plot(long,lat,'w','linewidth',2)
subplot(233)
pcolor(lon_can,lat_can,squeeze(pr_can1(:,:,2))')
shading interp
caxis([0 30]);
axis([65 100 0 40])
hold on
load coast
plot(long,lat,'w','linewidth',2)
subplot(234)
pcolor(lon_uk,lat_uk,squeeze(pr_uk1(:,:,2))')
shading interp
caxis([0 30]);
axis([65 100 0 40])
hold on
load coast
plot(long,lat,'w','linewidth',2)
subplot(235)
pcolor(lon_ind,lat_ind,squeeze(pr_ind1(:,:,2))')
shading interp
caxis([0 30]);
axis([65 100 0 40])
hold on
load coast
plot(long,lat,'w','linewidth',2)
set(gcf,'color','w');

Réponses (1)

Luca Ferro
Luca Ferro le 3 Avr 2023
Modifié(e) : Luca Ferro le 3 Avr 2023
'dir' returns an empty structure since for whatever reason, most likely a path issue, it cannot find the said files.
The empty structure has a property 'name', which is empty as well and so the assignment cannot be performed. You can check this by debugging with a breakpoint on line:
fname1=fns1.name;
To solve the issue i would double check the path and the availability of the files.
Another suggestion i give you is to use arrays of structs instead of several variables with numbers in their names (you can do this since 'dir' returns structures with the same fields, so:
fns(1)=dir('Aus pr_Amon_ACCESS-CM2_ssp126_r1i1p1f1_gn_20150616-20990916_v20191108.nc'); %%%%%Australia
fns(2)=dir('Ger pr_Amon_AWI-CM-1-1-MR_ssp126_r1i1p1f1_gn_20150616-20990916_v20190529.nc'); %%%%%Germany
fns(3)=dir('pr_Amon_CanESM5-CanOE_ssp126_r1i1p2f1_gn_20150616-21000916_v20190429.nc'); %%%%%Canada
fns(4)=dir('pr_Amon_UKESM1-0-LL_ssp126_r1i1p1f2_gn_20150616-21000916_v20190503.nc'); %%%%%UK
fns(5)=dir('Ind pr_Amon_IITM-ESM_ssp126_r1i1p1f1_gn_20150616-20990916_v20201112.nc'); %%%%%India
Or if those are the only .nc files present in your folder, a one line would do the trick:
fns=dir('pathToYourFolder\*.nc')
Doing so instead of rewriting the same lines for each variable you can just easily loop them reducing the code size to 1/5 of the original.

Catégories

En savoir plus sur View and Analyze Simulation Results dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by