Filtering data from Struct in Matlab - matlab

S.o = [{'A'} ,{'B'}, {'C'}];
S.p.q = [{'q1'}, {'q2'}, {'q3'}];
S.p.q.a = [-1,-2,-3];
S.p.q.b = [10,20,30];
How do i create another struct (S_filter) in Matlab for S.o = 'A' or 'C' only:
S_filter.o = [{'A'} ,{'C'}];
S_filter.p.q = [{'q1'}, {'q3'}];
S_filter.p.q.a = [-1,-3];
S_filter.p.q.b = [10,30];
Thanks

Related

Entry data form

I'm creating a data entry form to a database sheet, previously I've managed to create a single cell data entry form. But now I'm going to create a data entry form that is entered in the range B6:N10. How do I modify it?
function SIMPAN1() {
var Sheet = SpreadsheetApp.openById("1hnezkq89bgVUvimYDdAfWDVY01f7ekFN3T6TY3Ui6oA");
var sheetInput = Sheet.getSheetByName('INPUT');
var sheetDb = Sheet.getSheetByName('DATABASE');
var lastRow = sheetDb.getRange("B1").getDataRegion().getLastRow();
lastRow += 1
var data1 = [[tgl1 = sheetInput.getRange('B6').getValue(),
nama1 = sheetInput.getRange('C6').getValue(),
kls1 = sheetInput.getRange('D6').getValue(),
srthfl1 = sheetInput.getRange('E6').getValue(),
aythfl1 = sheetInput.getRange('F6').getValue(),
nilaithfz1 = sheetInput.getRange('G6').getValue(),
jldsrt1 = sheetInput.getRange('H6').getValue(),
hlmayt1 = sheetInput.getRange('I6').getValue(),
mtri1 = sheetInput.getRange('J6').getValue(),
nilaitrtl1 = sheetInput.getRange('K6').getValue(),
prgst1 = sheetInput.getRange('L6').getValue(),
prgda1 = sheetInput.getRange('M6').getValue(),
ket1 = sheetInput.getRange('N6').getValue(),]];
sheetDb.getRange("B" + lastRow + ":N" + lastRow).setValues(data1);
}
Try this:
function SIMPAN1() {
const ss = SpreadsheetApp.openById("ssid");
const ish = ss.getSheetByName('INPUT');
const dsh = ss.getSheetByName('DATABASE');
const ivs = ish.getRange(6, 2, 1, 13).getValues();
dsh.getRange(dsh.getLastRow() + 1, 2, ivs.length, ivs[0].length).setValues(ivs);
}

sum nested data with swift

I am trying to sum nested data without success.
This is my data:
{
"BON_PK" = 34;
"BON_EXTRA" = "100.00";
Line = ({ "LIG_PRICE" = "40.80";},
{ "LIG_PRICE" = "40.80";})
},
{
"BON_PK" = 35;
"BON_EXTRA" = "10.00";
Line = ({"LIG_PRICE" = "40.80";},
{"LIG_PRICE" = "40.80";})})
This is what I tried:
vPrice = vArr.map {$0?.Line!.map {(($0.LIG_PRICE as NSString).floatValue)}}.reduce(0, +)
This one is working but not the nested one:
vDelTotal = vArrBon.map { ($0?.BON_EXTRA!.toFloat)! }.reduce(0, +)
I created a 'toFloat' Function that is not working with the nested one.
I have this error message:
Cannot convert value of type '[Float]?' to closure result type 'Float'

Swift, dictionary parse error

I'm using an API to get weather condition and the retrieved dict is
dict = {
base = stations;
clouds = {
all = 92;
};
cod = 200;
coord = {
lat = "31.23";
lon = "121.47";
};
dt = 1476853699;
id = 1796231;
main = {
"grnd_level" = "1028.63";
humidity = 93;
pressure = "1028.63";
"sea_level" = "1029.5";
temp = "73.38";
"temp_max" = "73.38";
"temp_min" = "73.38";
};
name = "Shanghai Shi";
rain = {
3h = "0.665";
};
sys = {
country = CN;
message = "0.0125";
sunrise = 1476827992;
sunset = 1476868662;
};
weather = (
{
description = "light rain";
icon = 10d;
id = 500;
main = Rain;
}
);
wind = {
deg = "84.50239999999999";
speed = "5.97";
};
}
If I want the value of humidity, I just use
let humidityValue = dict["main"]["humidity"] and it works.
But the problem is I also want to get the value of description in weather
when I used let dscptValue = dict["weather"]["description"]
it retrieved nil.
How's that? and I notice there are two brackets around weather .I'm not sure whether it is the same with the statement without brackets.
weather = (
{
description = "light rain";
icon = 10d;
id = 500;
main = Rain;
}
);
How to get the value of description?
weather keys contains Array of Dictionary not directly Dictionary, so you need to access the first object of it.
if let weather = dict["weather"] as? [[String: AnyObject]], let weatherDict = weather.first {
let dscptValue = weatherDict["description"]
}
Note: I have used optional wrapping with if let for preventing crash with forced wrapping.
Weather is an array of dictionaries.
dict["weather"][0]["description"]
may give you the expected result.

Syntax for Swift 2 for directions step loop

Can anyone help with the syntax for this loop in Swift 2. The code is from a very useful tutorial ( http://www.devfright.com/category/map-kit-framework/mkdirectionsrequest/) which covers the route directions but it's in Objective C and I know that a number of elements are now deprecated, such as ++. I'm having problems converting the first two lines of code to Swift 2. Any help much appreciated.
for (int i = 0; i < routeDetails.steps.count; i++) {
MKRouteStep *step = [routeDetails.steps objectAtIndex:i];
NSString *newStep = step.instructions;
self.allSteps = [self.allSteps stringByAppendingString:newStep];
self.allSteps = [self.allSteps stringByAppendingString:#"\n\n"];
self.steps.text = self.allSteps;
}
If you don't need the index explicitly, forget index loops.
for step in routeDetails.steps {
let newStep = step.instructions
allSteps += "\(newStep)\n\n"
steps.text = allSteps
}
or still swiftier
allSteps += routeDetails.steps.map({$0.instructions}).joinWithSeparator("\n\n")
steps.text = allSteps
In Swift 2:
for i in 0..< routeDetails.steps.count {
var step: MKRouteStep = routeDetails.steps[i]
var newStep: String = step.instructions
self.allSteps = self.allSteps.stringByAppendingString(newStep)
self.allSteps = self.allSteps.stringByAppendingString("\n\n")
self.steps.text = self.allSteps
}
For anyone else using the route.step instructions this is how I placed it in a text field on a map. Many thanks to Vardian for solving the problem.
self.allSteps += route.steps.map({$0.instructions}).joinWithSeparator("\n\n")
self.directionsText.text = self.allSteps

Filter array using predicate

I need to filter following array with status equal to "U" and i have used following.
NSArray *result = [alertModified.senders filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(subscriptions.status = %#)",#"U"]];
But I'm getting empty arrays.
Please help me on filtering this?
Array String:
(senderCode = CPFB, senderName = CPFB, forSenderLevel = 0, subscriptions = (
"correspondenceListId = 102,status = S,senderCode = AA,subject = Letter,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ",
"correspondenceListId = 103,status = U,senderCode = BB,subject = Nomination Letters,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ",
"correspondenceListId = 104,status = U,senderCode = AA,subject = Yearly statements,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ",
"correspondenceListId = 105,status = U,senderCode = BB,subject = All Future Letters,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = "))
In your example you should be filtering the subscription list itself, not the whole senders. You have to apply the filter to each sender. Try changing your filter line to this and check if it gives you results:
NSArray *result = [[alertModified.senders objectAtIndex:0].subscriptions filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(status = %#)",#"U"]];