How do I extract a string value from a cell so I can check its datatype? Intro Matlab Q - string

Part of my assignment is testing what datatype is stored in my "studentNames" variable.
However I believe that because the studentNames are being held within a cell that MATLAB cant detect the datatype.
How could I solve this problem?
Editor Window
function [studentCell] =classCellArray(studentNames, studentIDs, studentGrades)
studentCell(1,:) = [ **studentNames{1,:}** studentIDs(1,:) studentGrades(1,:) {mean(studentGrades(1,:))}];
studentCell(2,:) = [ studentNames{2,:} studentIDs(2,:) studentGrades(2,:) {mean(studentGrades(2,:))}];
studentCell(3,:) = [ studentNames{3,:} studentIDs(3,:) studentGrades(3,:) {mean(studentGrades(3,:))}];
studentCell(4,:) = [ studentNames{4,:} studentIDs(4,:) studentGrades(4,:) {mean(studentGrades(4,:))}];
Command window
studentCell =
'Ali' 'G10293' [1x3 double] [82.6667]
'Yin' 'G10498' [1x3 double] [ 93]
'Bob' 'G10201' [1x3 double] [56.6667]
'Jim' 'G19532' [1x3 double] [ 100]
EDU>> class(studentNames)
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.**

Related

MSSQL module converting return value to int?

We are using the MSSQL module with Node.js.
I am running the following query:
SELECT AVG((RAT_VALUE * 1.0)) FROM RAT WHERE RAT_PER_ID_FROM IS NOT NULL AND RAT_PER_ID_ABOUT = 139 AND RAT_USE = 'Y' AND RAT_ABOUT_ROLE = 'RS' AND RAT_DATE_INSERTED >= '10/1/2018' AND RAT_DATE_INSERTED < '10/1/2019'
If I run this against the database directly, it returns:
4.45
The output from MSSQL is:
4
The exact resultset returned is:
results { recordsets: [ [ [Object] ] ],
recordset: [ { '': 4 } ],
output: {},
rowsAffected: [ 1 ] }
In other words, MSSQL is always returning the value 4, instead of 4.45.
The column type od RAT_VALUE is INT in the database but I've tried changing it to DECIMAL(5, 2) without any luck.
I've tried explicitly returning a DECIMAL from the query like:
SELECT CAST(AVG((RAT_VALUE * 1.0)) AS DECIMAL(5, 2)) ...
But no luck there either.
It seems MSSQL is simply clipping and dropping the decimal part of any number, even numbers of Decimal types.
I even set the value as 4.75 in the database and returned it directly and it still returns 4.
Any ideas out there?

Write Past Value in data.txt

I want to write some list in data.txt.
The output from program is:
Triangle
('(a1, b1)', '(a2, b2)', '(a3, b3)')
Triangle
('(a4, b4)', '(a5, b5)', '(a6, b6)')
With this lines of code to write in data.txt;
data = {}
data['shapes'] = []
data['shapes'].append({
'name': str(triangle.name),
'Vertices': list(triangle.get_points())
I need output in my data.txt with json format like this:
{"shapes": [{"name": "Triangle", "Vertices": ["(a1, b1)", "(a2, b2)", "(a3, b3)"]}, {"name": "Triangle", "Vertices": ["(a4, b4)", "(a5, b5)", "(a6, b6)"]}]}
But this is what I get:
{"shapes": [{"name": "Triangle", "Vertices": ["(a4, b4)", "(a5, b5)", "(a6, b6)"]}]}
So, how can I write the past value of triangle that have vertices (a1, b1)...(a3, b3)?
This part of your code should be executed only once:
data = {}
data['shapes'] = []
The following part of your code you should execute repeatedly
data['shapes'].append({
'name': str(triangle.name),
'Vertices': list(triangle.get_points())
probably in a loop similar to this one
for triangle in triangles:
data['shapes'].append({
'name': str(triangle.name),
'Vertices': list(triangle.get_points())
It seems like you're overwriting the variable referencing the first triangle object with the next triangle object before appending the first triangle object's information to data['shapes'].
That block of code where you append to your data['shapes'] should be executed twice, once for each triangle object.

how to initialize list of lists of lists with unknown dimensions

Here d is a list of lists of lists with structure like this
[
[
[vocab[START], vocab["image1"], vocab["caption1"], vocab[END]],
[vocab[START], vocab["image1"], vocab["caption2"], vocab[END]],
...
],
...
]
I don't know the dimensions already therefore I have problem in initializing, keeping an upper limit I could have used the xrange function like this
d=[[[[] for k in xrange(50)] for j in xrange(10)] for i in xrange(8769)]
but I'm working in Python3 and xrange is depreciated. The code goes like this
for i in range (len(t)):
for j in range (len(t[i])):
d[i][j][0]=vocab[START]
for k in range(len(t[i][j])):
if t[i][j][k] not in list(vocab.keys()):
d[i][j][k+1]=vocab[UNK]
else:
d[i][j][k+1]=vocab[t[i][j][k]]
Any help on this is appreciated.

running Discrete wavelet transform in R Language

Please can someone help with a solution for running Discrete wavelet transform in R.
I have tried with the following data format; Year, Rain.
Year is in form of 1970,1972,1973.... and Rain in form of 200, 85, 34, 56 23, 0.5... etc. I don't know if my data frame is correct. or if i need to do something to the data before I run it.
Haven't saved the data.frame as wave, I ran as:
rain.dwt.01 <- wavDWT(wave)
Here is my code:
getwd()
setwd("C:\\Users\\dell\\Desktop\\ANN")
wave<-read.csv(file.choose(),header = T)
library(wmtsa)
library(wavelets)
library(waveslim)
library(MASS)
library(wavethresh) ### loaded auxillary functions from Internet
con <- url("faculty.washington.edu/dbp/R-CODE/workshop.Rdata")
print(load(con))
close(con)
lplot(wave)
abline(h=mean(wave),lty="dotted",col="red")
rain.dwt.01 <- wavDWT(wave)
I got this error:
Error in itCall("RS_wavelets_transform_discrete_wavelet_convolution", :
(list) object cannot be coerced to type 'double
Please help with example so I can understand why this error appears

Interleave blocks, or make object out of two blocks (field names and values)

Instead of creating objects by writing:
obj: object [
name: "Fork"
id: 1020
]
I'd like to write something like...
obj: something-or-another [name id] ["Fork" 1020]
...and get the same result. An ideal solution would also permit:
obj: something-or-another [name: id:] ["Fork" 1020]
Easy enough to write a something-or-another, but does this fit something already "in the box"?
I don't believe there's a baked-in way to do this. Not difficult though:
func [words values][
set words: context append map-each word words [to set-word! word] none values
words
]
I suppose I could break this down a little:
func [
"Creates an Object From a Block of Words, Assigns Values"
words [block!] "Words used to create object"
values "Value(s) to assign"
][
words: map-each word words [to set-word! word] ; The requisite set-words
append words none ; Initial value for all words
words: context words ; Create our object
set words values ; Assigns our value(s) to the object
words ; returns the object
]
You might employ a different method to interleave blocks, such as:
func [words [block!] values [block!]][
collect [
repeat index max length? words length? values [
keep words/:index
keep values/:index
]
]
]
Here's something that requires at least Rebol 3:
func [
"Create an object based on some words and values."
words [any-word! block!] "Word or block of words"
values [any-type!] "Value or block of values"
/local object
][
object: make object! either block? words [length? words] [1]
set bind/copy/new :words object :values
object
]
If you want to also allow setting unset values, try this:
func [
"Create an object based on some words and values."
words [any-word! block!] "Word or block of words"
values [any-type!] "Value or block of values"
/any "Allows setting words to any value, including unset"
/local object
][
object: make object! either block? words [length? words] [1]
apply :set [bind/copy/new :words object :values any]
object
]
Both of these create objects with self, so if you want to create an object without self you have to do some fancier tricks. See the selfless proposal for details.
I wrote a similar function (Rebol2) just a few days ago:
build-object: func [
"Builds an object from a block"
names [block!] "Field names"
/values val [block!] "Initial values"
/local o name value
] [
o: copy []
names: compose names
o: either values [
parse names [
some [
set name [word! | set-word!]
(append o to-set-word name)
| skip
]
]
set/pad reflect o: context append o none 'words val
o
] [
if any [
parse names [
some [
set name [word! | set-word!]
(append o reduce [to-set-word name none])
]
]
parse names [
(clear o) some [
set name [word! | set-word!] set value any-type!
(append o reduce [to-set-word name :value])
]
]
] [context o]
]
o
]
To build your object you could write any of: (create a function as f: does ["x"])
build-object [name "Fork" id 1020]
build-object [name: "Fork" id: 1020]
build-object/values [name id] ["Fork" 1020]
build-object/values [name: id:] ["Fork" 1020]
build-object [name f]
build-object [name (f)] ;block is composed
build-object [name 5 id f]
build-object [name 5 id 'f]
You can also make objects with fields set to none if you leave the values out, e.g. with
build-object [name id]

Resources