Complete expression for matrix operator
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Madison
le 19 Juil 2023
Modifié(e) : Dyuman Joshi
le 19 Juil 2023
When I change a paraenthesis to bracket I recieve an error, but when I use brackets I recieve another error
Parathesis:
File: untitled.m Line: 51 Column: 34
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or
other syntax error. To construct matrices, use brackets instead of parentheses.
Brackets:
% check this, which depth level do you want?
% Which is the surface and which is the bottom?
% are the layers a consistent depth?
% this info should be in some supporting document on CMEMS
depth=ncread(fullfile(fp,'June2021.nc'),'depth');
% change this depending on how many vertical levels you need to calculate
% if you want lots of depth layers you'll need to amend the loop below
% this is an example, pulling out the second depth layer
nz=2;
% change this to how many years you want to run this loop over
ystart=1972;
yend=2022;
nyear=yend-ystart+1
for yi=1:nyear
ny=ystart+yi-1
filename=[fullfile(fp,'June' num2str(ny) '.nc')];
u1 = ncread(filename,'uo',[1 1 nz 1],[length(lon) length(lat) 1 ntime]);
v1 = ncread(filename,'uo',[1 1 nz 1],[length(lon) length(lat) 1 ntime]);
% if you want monthly averages, do this
% note this will end up a different dimension if you're extracting
% multiple layers
% might want to predefine these matrices depending on what you want
% https://uk.mathworks.com/help/matlab/ref/mean.html
u2(:,:,yi)=mean(u1,[4]); whos u2
v2(:,:,yi)=mean(v1,[4]);
end
% then take the mean to get the mean over all the years, for one depth
% layer only, remember
u3=mean(u2,[3]); %taking the mean over the third dimension
v3=mean(u2,[3]);
% calculate the magnitude of the vel and plot
uv4=sqrt(u3.^2+v3.^2);
close all, pcolor(LON,LAT,uv4.'), shading flat, colorbar
0 commentaires
Réponse acceptée
Mrutyunjaya Hiremath
le 19 Juil 2023
use like this
filename= fullfile(fp,['June', num2str(ny), '.nc']);
2 commentaires
Dyuman Joshi
le 19 Juil 2023
Modifié(e) : Dyuman Joshi
le 19 Juil 2023
Please copy and paste the full error message i.e. all of the red text.
Also, you are missing a set of parenthesis in the definition of variable v1.
% v v
v1 = ncread(fullfile(filename,'uo',[1 1 nz 1],[length(lon) length(lat) 1 ntime]));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Visualization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!