I'm using Matlab 2016a on my university's cluster. My local PC has Matlab 2016b installed.
I'm attempting to do a very large regression using cellfun. The drought resistance and predictor layers are 2044x1572. The internal dimensions of "drought resistance" is 100x1 while the internal dimensions of "predictors" is 100x6, representing the different predictors for each cell.
d_regress=cellfun(#(x,y)regress(x,y),Drought_resistance,predictors,'UniformOutput',false);
When I run this code with sample data on my local PC I get no errors.
However, when I run this code on the cluster I get the error:
Error using *
Inner matrix dimensions must agree.
Error in regress (line 93)
b(perm) = R \ (Q'*y);
Error in #(x,y)regress(x,y)
So then I fix the inner matrix dimensions so that they are 1x100 and 100x6.
Then I get the following error, which makes sense because of how regress works.
Error using |
Matrix dimensions must agree.
Error in regress (line 66)
wasnan = (isnan(y) | any(isnan(X),2));
Error in #(x,y)regress(x,y)
I've been having to use mldivide on the cluster in order to do my regressions (mldivide gives me no errors), but I would prefer to use regress due to its additional functionality. Is there any way I can modify my code in order to use regress?
Related
I seem to have a really stupid problem but I cannot figure it out.
I have this expression in matlab
ref_phys = #(x,y, csi) B(x,y) * csi + b(x,y);
On my laptop everything is fine, but moving it into another system which runs a 2016 version of Matlab, I get
Error using +
Matrix dimensions must agree.
Error in L2_proj_2D>#(x,y,csi)B(x,y)*csi+b(x,y) (line 39)
ref_phys = #(x,y, csi) B(x,y) * csi + b(x,y);
And since nothing has changed from my laptop code, I'm 100% sure that the matrix dimenions agree.
B(x,y) has dymension 2-by-2
csi has dimension 2-by-3
b(x,y) has dimension 2-by-1
Thus everything should give a 2-by-3 matrix
Could it be the version of matlab? How can I solve it ?
Thanks!
I am trying to perform PCA on the MNIST data set. I have the following code so far.
...load data into MATLAB
% Centre data matrix
imagesMean = mean(images);
imagesShifted = images - imagesMean;
% Compute covariance matrix of mean shifted images
covariance = cov(imagesShifted);
Trying to do this gives me the following response:
Out of memory. Type "help memory" for your options.
Error in cov (line 155) c = (xc' * xc) ./ denom;
Error in PCA (line 27) covariance = cov(imagesShifted);
imagesShifted is a 784x60000 double matrix.
I am using a MacBook Pro 2015 with 16GB RAM and a 2.8 GHz processor and a dedicated graphics card.
I looked under the help menu for the memory command but the information only seems relevant to Windows machines. Also looked at the MathWorks website for resolving out of memory issues but wasn't sure how to proceed based on that information.
How can I get around this issue?
For large data sets, I suggest you to use the princomp function of matlab, with the flag 'econ' activated.
https://es.mathworks.com/help/stats/princomp.html
Or the pca function with the flag 'economy' or indicating the 'NumComponents' you wish.
https://es.mathworks.com/help/stats/pca.html
on my PC, I use R2014a and my script runs fine. The simulation server of my university runs R2012a and there a get an error running my script.
Here is the error:
Warning: The default trust-region-reflective algorithm does not solve
problems with the constraints you have specified. FMINCON will use the
active-set algorithm instead. For information on applicable
algorithms, see Choosing the Algorithm in the documentation.
Error using svd Input to SVD must not contain NaN or Inf.
Error in pinv (line 29) [U,S,V] = svd(A,0);
Error in qpsub (line 463)
projSD = pinv(projH)*(-Zgf);
Error in nlconst (line 619)
[SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
Error in fmincon (line 794)
[X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Error in simulation_coop (line 85)
[q, fval] = fmincon(neg_aux_fun, q0, [], [], [], [], [], ub, #(q)constraints( q, a_t, b_t, W, p_cell_lin, ss_lin,
h_cell2bs(:,:,n),
h_trans2bs(:,:,n), rate ),options);
With R2014a I get neither the warning nor the error. So do you have any idea what the problem might be?
This answer is more of a how-to:
First of all, check that you run your scripts on exactly the same data. Different data (type, size, values) might yield different results.
Check the release notes of the Optimization Toolbox. If there were any significant changes in it between R2012a and R2014a, you'll find those mentioned in the one/several of the release notes of the toolbox for R2012b, R2013a, R2013b or R2014b versions. Here is the list: http://de.mathworks.com/help/optim/release-notes.html
Later edit
As you may see in the page linked above, R2012b changes the default algorithm for fmincon.
I am running a MATLAB code which solves a set of non-linear simultaneous equations. The code can be found here. The data input for the code (in excel) can be found here.
I encounter the following error:
Error using sym/subsasgn (line 733)
Indexed assignment to empty SYM objects is supported only in the 0-by-0 case.
Error in Solution (line 69)
x(i,:) = (b(i,1) - b0)./(c(i,1)*x0) + c0/c(i,1);
Does anyone have any idea how I can resolve this?
When declaring a symbolic variable, you have to specify the dimensions, otherwise it's a scalar. Instead of syms x; use sym and set the dimension argument:
x=sym('x',[3,4])
Replace [3,4] with the dimensions you want.
I am trying to solve a large DAE system, coupled with the equations to calculate the sensitivity of the variables to a parameter. My problem is the jacobian of the entire system, its calculation is pretty slow and I would like to speed it up.
I am using numjac, in this form:
[Jx,FAC,G] = numjac(#(t,y)MODEL(t,y,X),tt,yy,dydt,jac_tol,FAC,0,JPat,G);
I want to vectorize the code, but I can't seem to get what this means. As far as I understood my code is already vectorized! t,y,X go in and I get a column vector of dy(i)/dt, or F(t,y(i)). But if I say that my function is vectorized, I get an error:
Matrix dimensions must agree.
Error in numjac (line 192)
Fdiff = Fdel - Fty(:,ones(1,ng));
How can I properly vectorize it?