Brace indexing error when using MATLAB cell2mat() function
I can't understand why I'm suddenly getting an error even though I've used cell2mat in the same way for prior codes. The error reads
Brace indexing is not supported for variables of this type.
Error in cell2mat
cellclass = class(c{1});
And the corresponding code is
clear all;
close all;
clc;
parta = xlsread('C:\Users\Zahin\Desktop\Fall 2018\MEC 516\Lab 9\Data.xlsx',1,'A3:R15');
partb = xlsread('C:\Users\Zahin\Desktop\Fall 2018\MEC 516\Lab 9\Data.xlsx',2,'A3:K11');
a_rg = cell2mat(parta(:,1));
My goal is to turn these cells into column vectors so that I can use the plot function. When I do something like:
plot(parta(:,1),parta(:,2));
MATLAB will create a line plot that connects each point in the order of the array element index (i.e., (x1,y1) to (x2,y2) even if (x3,y3) would be closer to (x1,y1) in a linear fit). I can't understand why this occurs, but I assume its related to the fact that I can't convert the table arrays.
1 answer

If you use xlsread with only 1 return argument as:
num = xlsread(filename, sheet);
,the return value will be numeric matrix, hence you cannot convert the numeric matrix using the cell2mat function. What you probably used before is:
[num, txt, raw] = xlsread(filename, sheet);
,which returns cell arrays for second and third return value, since
txt
will read all cells that contain only text data, and place it in cell matrix, andraw
will read all data, and again place it in cell matrix, mixing numbers and character arrays.
See also questions close to this topic

Is there a faster way to compute element wise exponentials of a matrix in Matlab?
I am profiling my code and this one line seems to be a bottleneck. The idea is to create a spatial correlation matrix of n observations of a given dimension, based upon a theta vector of the same dimensionwhich contains dimensional hyperparameters to be fit.
In my overall code this spatial correlation function is called thousands of times (per iteration) while computing a likelihood function in order to optimize my theta parameters. The number of observations grows by one in each iteration of the overall code, and the theta parameters must be refit each iteration. So you can see how this line of code becomes crucial as the algorithm progresses.
I think that the slowest line, i.e.,
R = exp(sum(bsxfun(@times, abs(D_X).^corr_model,reshape(theta,[1 1 d])),3));
takes the most time to compute the final elementwise exponential across the resulting n by n matrix (the n by n matrix is yielded after summing over the 3 dimension of the distance matrix). But there is a lot going on in this line, so I am unsure if this is the most critical aspect to the overall performance.Thanks for any insight you may have!
I have already replaced a
repmat
command with absxfun
, to multiply the given thetas across the dimensional distance matrixD_X
, which sped up the code notably. However, nesting a secondbsxfun
to execute the squaring of distances i.e., to replaceabs(D_X).^corr_model
, made the code run slower.n = 500; dimension = 20; D_X = repmat(rand(n),[1 1 dimension]); theta = rand(dimension, 1); corr_model = 2; R = corr(corr_model,theta, D_X); function R = corr(corr_model,theta,D_X) % calculate the correlation matrix for the modified nugget effect model % corr_model  the correlation model used for the spatial correlation % corr_model = 2: gaussian correlation function % theta  vector of hyperparameters % D_X  the distance matrix for the input locations d = size(theta,1); switch corr_model case 2 %Gaussian correlation function R = exp(sum(bsxfun(@times, abs(D_X).^corr_model,reshape(theta,[1 1 d])),3)); end end

pinv(H) is not equal to pinv(H'*H)*H'
I'm testing the
y = SinC(x)
function with single hidden layer feedforward neural networks (SLFNs) with 20 neurons.With a SLFN, in the output layer, the output weight(OW) can be described by
OW = pinv(H)*T
after adding regularized parameter
gamma
, whichOW = pinv(I/gamma+H'*H)*H'*T
with
gamma > Inf, pinv(H'*H)*H'*T == pinv(H)*T, also pinv(H'*H)*H' == pinv(H).
But when I try to calculate
pinv(H'*H)*H'
andpinv(H)
, I find a huge difference between these two when neurons number is over 5 (under 5, they are equal or almost the same).For example, when
H
is10*10
matrix,cond(H) = 21137561386980.3
,rank(H) = 10
,H = [0.736251410036783 0.499731137079796 0.450233920602169 0.296610970576716 0.369359425954153 0.505556211442208 0.502934880027889 0.364904559142718 0.253349959726753 0.298697900877265; 0.724064281864009 0.521667364351399 0.435944895257239 0.337878535128756 0.364906002569385 0.496504064726699 0.492798607017131 0.390656915261343 0.289981152837390 0.307212326718916; 0.711534656474153 0.543520341487420 0.421761457948049 0.381771374416867 0.360475582262355 0.487454209236671 0.482668250979627 0.417033287703137 0.329570921359082 0.315860145366824; 0.698672860220896 0.565207057974387 0.407705930918082 0.427683127210120 0.356068794706095 0.478412571446765 0.472552121296395 0.443893207685379 0.371735862991355 0.324637323886021; 0.685491077062637 0.586647027111176 0.393799811411985 0.474875155650945 0.351686254239637 0.469385056318048 0.462458480695760 0.471085139463084 0.415948455902421 0.333539494486324; 0.672003357663056 0.607763454504209 0.380063647372632 0.522520267708374 0.347328559602877 0.460377531907542 0.452395518357816 0.498449772544129 0.461556360076788 0.342561958147251; 0.658225608290477 0.628484290731116 0.366516925684188 0.569759064961507 0.342996293691614 0.451395814182317 0.442371323528726 0.525823695636816 0.507817005881821 0.351699689941632; 0.644175558300583 0.648743139215935 0.353177974096445 0.615761051907079 0.338690023332811 0.442445652121229 0.432393859824045 0.553043275759248 0.553944175102542 0.360947346089454; 0.629872705346690 0.668479997764613 0.340063877672496 0.659781468051379 0.334410299080102 0.433532713184646 0.422470940392161 0.579948548513999 0.599160649563718 0.370299272759337; 0.615338237874436 0.687641820315375 0.327190410302607 0.701205860709835 0.330157655029498 0.424662569229062 0.412610204098877 0.606386924575225 0.642749594844498 0.379749516620049]; T=[0.806458764562879 0.251682808380338 0.834815868451399 0.750626822371170 0.877733363571576 1 0.626938984683970 0.767558933097629 0.921811074815239 1]';
There is a huge difference between
pinv(H'*H)*H*T
andpinv(H)*T
, wherepinv(H'*H)*H*T = [4803.39093243484 3567.08623820149 668.037919243849 5975.10699147077 1709.31211566970 1328.53407325092 1844.57938928594 22511.9388736373 2377.63048959478 31688.5125271114]'; pinv(H)*T = [19780274164.6438 3619388884.32672 76363206688.3469 16455234.9229156 135982025652.153 93890161354.8417 283696409214.039 193801203.735488 18829106.6110445 19064848675.0189]'.
I also find that if I round
H
,round(H,2)
,pinv(H'*H)*H*T
andpinv(H)*T
return the same answer. So I guess one of the reason might be the float calculation issue inside the matlab.But since
cond(H)
is large, any small change ofH
may result in large difference in the inverse ofH
. I think theround
function may not be a good option to test. As Cris Luengo mentioned, with largecond
,the numerical imprecision will affect the accuracy of inverse.In my test, I use 1000 training samples with noise between
[0.2,0.2]
, and test samples are noise free. 20 neurons are selected. TheOW = pinv(H)*T
can give reasonable results forSinC
training, while the performance forOW = pinv(H'*H)*T
is worse. Then I try to increase the precision ofH'*H
bypinv(vpa(H'*H))
, there's no significant improvement.Does anyone know how to solve this?

Is there a stepbystep description that enables me to produce a sensor error model for an IMU?
I've noticed sensor error models produced within the following for the IMU used:
1) http://hdl.handle.net/2027.42/58460
2) Ferraris, F., Grimaldi, U., & Parvis, M. (1995). Procedure for effortless infield calibration of threeaxis rate gyros and accelerometers. Sensors and Materials, 7, 311311.
However, I'm still unclear as to how to create the sensor models for the MEMS IMU for a commercial device. Any resources that help me go through it stepbystep in layman terms?

python/mathplotlib plot equivalent of R's symbol plot?
Is there a python equivalent of this?
symbols package:graphics R Documentation
Draw Symbols (Circles, Squares, Stars, Thermometers, Boxplots)
Description:
This function draws symbols on a plot. One of six symbols; circles, squares, rectangles, stars, thermometers, and boxplots, can be plotted at a specified set of x and y coordinates. Specific aspects of the symbols, such as relative size, can be customized by additional parameters.

Arrow not showing in pandas plot
enter image description hereI need an arrow in my plot, I tried to put in in but it won't show. I researched and could not find what I did wrong.
ax_google = df_stocks['GOOG'].plot(linewidth=5, color= "k", figsize=(9, 6)) ax_google.set_title("GOOGLE prices development", size=16, weight='bold') ax_google.set_xlabel('Date') ax_google.set_ylabel("Index") ax_google.legend(['GOOG']) ax_google.set_ylim(0,400) ax_google.set_xlim('20080101', '20100101'); arrow = {'facecolor':'black', 'width':2, 'shrink':0.05} ax.annotate('Bankruptcy of Lehman Brothers', xy=('20080915',245), xytext=('20090606',325), arrowprops=arrow);

Plotting 3D plane and vectors
I have a plane in 3 dimensions, which I have graphed using the persp function. I also have some three dimensional vectors plotted in 3 dimensions using arrows3D. I would like to have the arrows and plane plotted together.
I have searched for ways to merge plots and to add arrows to plots, but I did not find anything about combining these two types of plots. Below is a MWE to produce a plane and an arrow separately.
y < 1:5 z < outer(x,y, function(a,b) a+b) persp(x,y,z) arrows3D(0,0,0,1,1,1)

Why is MongoDB creating indexes for fields that don't exist within that schema?
TL;DR: I am having trouble with my mongo database seemingly creating indexes for my boards collection from fields from my users collection which is causing E11000 errors when I try to create a new board.
I am building a kanban board (like Jira) and have board, task and user collections (entity relationship diagram : https://imgur.com/a/Nu6Eg91). All of the collections work fine following a .dropIndexes(). However, when I have been working with tasks via the UI on one board, when I try to create another board I get this E11000 error:
{ MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: kanban.boards.$username_1 dup key: { : null } at Function.create (/home/ubuntu/workspace/kanban v1.0/node_modules/mongodbcore/lib/error.js:43:12) at toError (/home/ubuntu/workspace/kanban v1.0/node_modules/mongodb/lib/utils.js:149:22) at coll.s.topology.insert (/home/ubuntu/workspace/kanban v1.0/node_modules/mongodb/lib/operations/collection_ops.js:859:39) at /home/ubuntu/workspace/kanban v1.0/node_modules/mongodbcore/lib/connection/pool.js:532:18 at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickCallback (internal/process/next_tick.js:104:9) driver: true, name: 'MongoError', index: 0, code: 11000, errmsg: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: kanban.boards.$username_1 dup key: { : null }' }
This appears to be because of a null value in the username field in the board schema but there is no such field in this model as can be seen below:
// Board Schema // Config var mongoose = require("mongoose"), passportLocalMongoose = require("passportlocalmongoose"); // Create Board Schema var BoardSchema = new mongoose.Schema({ user: {type: mongoose.Schema.Types.ObjectId, ref: "User", unique: true, sparse: true}, todo: [{type: mongoose.Schema.Types.ObjectId, ref: "Task"}], inProgress: [{type: mongoose.Schema.Types.ObjectId, ref: "Task"}], testing: [{type: mongoose.Schema.Types.ObjectId, ref: "Task"}], completed: [{type: mongoose.Schema.Types.ObjectId, ref: "Task"}] }); // Validation BoardSchema.plugin(passportLocalMongoose); // Export Model module.exports = mongoose.model("Board", BoardSchema);
Here is an example board in the db:
{ "_id" : ObjectId("5c65767c8977670a2366ffe5"), "todo" : [ ObjectId("5c657a1e451bc80ac315ef35"), ObjectId("5c657a4a451bc80ac315ef37"), ObjectId("5c657a76451bc80ac315ef39") ], "inProgress" : [ ObjectId("5c6579e1451bc80ac315ef31"), ObjectId("5c657a03451bc80ac315ef33"), ObjectId("5c657a3a451bc80ac315ef36"), ObjectId("5c657a8a451bc80ac315ef3a") ], "testing" : [ ObjectId("5c657a9a451bc80ac315ef3b") ], "completed" : [ ObjectId("5c657a60451bc80ac315ef38"), ObjectId("5c65bb8f6f5b731aec27b4a7"), ObjectId("5c65bba06f5b731aec27b4a8"), ObjectId("5c657a11451bc80ac315ef34") ], "user" : ObjectId("5c65767b8977670a2366ffe4"), "__v" : 51 }
For some reason, I think a username index has been created by the database for the boards schema. The indexes for the boards collection are below:
[ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "kanban.boards" }, { "v" : 1, "key" : { "user" : 1 }, "name" : "user_1", "ns" : "kanban.boards", "background" : true }, { "v" : 1, "unique" : true, "key" : { "username" : 1 }, "name" : "username_1", "ns" : "kanban.boards", "background" : true } ]
For completeness, here is the user schema:
// User Schema // Config var mongoose = require("mongoose"), uniqueValidator = require("mongooseuniquevalidator"), passportLocalMongoose = require("passportlocalmongoose"); // Create User Schema var UserSchema = new mongoose.Schema({ username: {type: String, required: true, unique: true}, password: String }); // Validation and Hash/Salt PW UserSchema.plugin(uniqueValidator, {message: "A user is already registered with that {PATH}."}); UserSchema.plugin(passportLocalMongoose); // Export Model module.exports = mongoose.model("User", UserSchema);
The code causing the error is in the signup route, part of which is shown below:
// create new board for user var newBoard = { user: user._id, todo: [], inProgress: [], testing: [], review: [], completed: [], }; Board.create(newBoard, function(err, board) { if(err) { console.log(err); req.flash("error", "Uh oh! Something went wrong."); return res.redirect("/"); } // authenticate user passport.authenticate("local")(req, res, function() { req.flash("success", "Welcome to your Kanban board, " + user.username + "."); return res.redirect("/board"); }); });
I don't understand why this index is being created (or indeed if this is what is causing the E11000 errors but I'm pretty sure it is). Apologies for the spam of code, I am quite inexperienced with using mongo and so don't know what is relevant and what is not. I have built mongo databases with multiple collections before but not with a link collection as I have here so I can't work out what is going wrong. Please let me know if I have missed anything that is useful or important. Thanks.

indexOf() in Android when using Helper
I know that the below code gives the index of that particular element in java.
List<String> list = new ArrayList<>(); list .add("100"); Log.d("TAG",String.valueOf(list.indexOf("300")));
But how to get the index of an element while using a helper Class?
List<HelperClass> Arraylist= new ArrayList<>(); Arraylist.add(new HelperClass(name, email, phoneno)); Log.d("TAG", String.valueOf(new HelperClass(Arraylist.indexOf(name,email,phoneno))));
I searched everywhere for this but couldn't find. Can someone tell me how to find index of a particular item in arraylist while using modal to add data?
Obviously what I have tried is wrong and it shows red line under the whole line but I just typed that code for your understanding of what I want to achieve. Can someone give me a way please?
Helper
@Override public int hashCode() { int result = getName() != null ? getName().hashCode() : 0; result = 31 * result + (Email != null ? Emaail.hashCode() : 0); result = 31 * result + (PhoneNo!= null ? PhoneNo.hashCode() : 0); return result; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Helper)) return false; Helperthat = (Helper) o; if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false; if (Email != null ? !Email.equals(that.Email) : that.Email != null) return false; if (PhoneNo != null ? !PhoneNo.equals(that.PhoneNo) : that.PhoneNo != null) return false; }

Matrix and index on Python
I should write a function that receives a matrix of integers M of size N x N and two indices "ir" and "jc" and returns "True" if and only if, for each element x in the row "ir", M contains at least two elements equal to x outside both the "ir" line and the "jc" column. Why the list index is out of range?
def verifica(M, ir, jc): elementi_uguali = 0 for n in M[ir]: contatore = 0 for i in range(len(M)): for j in range(len(M[0])): if M[i][j] == n: if i != ir: if j != jc: contatore += 1 if contatore == 2: elementi_uguali += 1 break if elementi_uguali == len(M): return True verifica([[8,0,3,9,3], [2,3,6,3,1], [1,2,5,7,1], [6,9,2,5,3], [3,2,4,16]], 1, 2)