I hava an array list (RatingsList) containing below contents
<CFArray 0x910e1a0 [0x2952380]>{type = mutable-small, count = 8, values = (
0 : <CFString 0x910e0d0 [0x2952380]>{contents = "NR-Adult"}
1 : <CFString 0x910e0f0 [0x2952380]>{contents = "NC-17/TV-MA"}
2 : <CFString 0x910e110 [0x2952380]>{contents = "R"}
3 : <CFString 0x910e120 [0x2952380]>{contents = "PG-13/TV-14"}
4 : <CFString 0x910e140 [0x2952380]>{contents = "PG/TV-PG"}
5 : <CFString 0x910e160 [0x2952380]>{contents = "G/TV-G"}
6 : <CFString 0x910e170 [0x2952380]>{contents = "TV-Y/TV-Y7"}
7 : <CFString 0x910e190 [0x2952380]>{contents = "NR"}
we are comparing for PG-13
[RatingsList containsObject:#"PG-13"]
return false.
Of course it returns false. Your array doesn't contain "PG-13", although it does contain "PG-13/TV-14".
Use a simple NSPredicate.
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"SELF contains %#", aString];
NSArray *filteredArray = [RatingsList filteredArrayUsingPredicate:predicate];
if ([filteredArray count] > 0) return YES;
return NO;
Related
I am using cellfun with UniformOutput set to 0. This applies the specified function to each cell, returning the output as a cell in a cell array.
Each of these cells are a cell array with 1 row and 6 columns. For example, a cell array with two cells:
ans =
{
[1,1] =
{
[1,1] = 1
[1,2] = 1
[1,3] = 1
[1,4] = 9
[1,5] = hello
[1,6] = 3
}
[2,1] =
{
[1,1] = 1
[1,2] = 1
[1,3] = 1
[1,4] = -33
[1,5] = world
[1,6] = 3
}
}
I would like to know the most efficient way to convert this into the 2x6 cell array, i.e.:
ans =
{
[1,1] = 1
[1,2] = 1
[1,3] = 1
[1,4] = 9
[1,5] = hello
[1,6] = 3
[2,1] = 1
[2,2] = 1
[2,3] = 1
[2,4] = -33
[2,5] = world
[2,6] = 3
}
Use cat(1,data{:}) which uses the comma separated list data{:} to unpack the cell and cat to concatenate.
I want to establish a pair of indices =[row col] where
row = 4 * (n-1) + i and col = 4 * (m-1) + i
Explanation for i, m and n:
For n = 1 and m = 2, 3, 4, loop i = 1 : 4.
For n = 2 and m = 1, loop i = 1 : 4.
For n = 3 and m = 5, loop i = 1 : 4.
The outcome should be:
row = [1 1 1 2 2 2 3 3 3 4 4 4 5 6 7 8 9 10 11 12]
col = [5 9 13 6 10 14 7 11 15 8 12 16 1 2 3 4 17 18 19 20]
That is, I want to establish pairs of indices under different sets of n-m conditions.
My trial:
row = []; col = [];
n = 1;
for i = 1 : 4
for m = [2 3 4]
row = [row 4 * (n - 1) + i];
col = [col 4 * (m - 1) + i];
end
end
n = 2; m = 1;
for i = 1 : 4
row = [row 4 * (n - 1) + i];
col = [col 4 * (m - 1) + i];
end
n= 3; m = 5;
for i = 1 : 4
row = [row 4 * (n - 1) + i];
col = [col 4 * (m - 1) + i];
end
This works but indeed I have many n-m conditions and the looping for i = 1 : 4 appeared repeatedly which seems that can be simplified.
May I know if there are any elegant solutions to finish my objective?
I appreciate for your help.
You can use a bsxfun based solution for all those three cases -
ii = 1:4
row = reshape(bsxfun(#(A,B) 4 * (B-1) + A,ii,n'),1,[]) %//'
col = reshape(bsxfun(#(A,B) 4 * (B-1) + A,ii,m'),1,[]) %//'
The inputs would be as listed next.
Case #1:
m = [2, 3, 4]
n = ones(1,numel(m))
Case #2:
n = 2
m = 1
Case #3:
n = 3
m = 5
I would create a Matrix with all parameters, then apply the math once:
M=[...n m i
ones(3,1) (2:4).' (1:3).';...
2*ones(4,1) ones(4,1) (1:4).';...
3*ones(4,1) 5*ones(4,1) (1:4).';...
];
row = (4 * (M(:,1) - 1) + M(:,3)).';
col = (4 * (M(:,2) - 1) + M(:,3)).';
%alternative:
%index=(4 * (M(:,[1:2]) - 1) + M(:,[3,3])).'
I have problem on IPhone 5S with front camera output, the same session resolution like rear camera. (AVCaptureSessionPreset352x288) and kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange setting for kCVPixelBufferPixelFormatTypeKey.
I found some discussion on apple forum about exact issue, here is the link: https://discussions.apple.com/message/23079639#23079639
What is the problem?
Please Help.
Good output, rear-facing camera.
Printing description of imageBuffer:
<CVPixelBuffer 0xd5e2f30 width=352 height=288 pixelFormat=420v iosurface=0xd80e724 planes=2>
<Plane 0 width=352 height=288 bytesPerRow=352>
<Plane 1 width=176 height=144 bytesPerRow=352>
<attributes=<CFBasicHash 0xd5c3710 [0x3bf18ad0]>{type = immutable dict, count = 1,
entries =>
1 : <CFString 0x3bf971b4 [0x3bf18ad0]>{contents = "PixelFormatDescription"} = <CFBasicHash 0xb9fce0 [0x3bf18ad0]>{type = immutable dict, count = 7,
entries =>
0 : <CFString 0x3bf97164 [0x3bf18ad0]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
2 : <CFString 0x3bf97194 [0x3bf18ad0]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
3 : <CFString 0x3bf972c4 [0x3bf18ad0]>{contents = "ContainsAlpha"} = <CFBoolean 0x3bf18e88 [0x3bf18ad0]>{value = false}
5 : <CFString 0x3bf97184 [0x3bf18ad0]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
7 : <CFString 0x3bf972d4 [0x3bf18ad0]>{contents = "Planes"} = <CFArray 0xb24830 [0x3bf18ad0]>{type = mutable-small, count = 2, values = (
0 : <CFBasicHash 0xb99420 [0x3bf18ad0]>{type = mutable dict, count = 3,
entries =>
0 : <CFString 0x3bf973b4 [0x3bf18ad0]>{contents = "FillExtendedPixelsCallback"} = <CFData 0xba06a0 [0x3bf18ad0]>{length = 12, capacity = 12, bytes = 0x00000000917cbb3100000000}
1 : <CFString 0x3bf97334 [0x3bf18ad0]>{contents = "BlackBlock"} = <CFData 0xb9deb0 [0x3bf18ad0]>{length = 1, capacity = 1, bytes = 0x10}
2 : <CFString 0x3bf97324 [0x3bf18ad0]>{contents = "BitsPerBlock"} = <CFNumber 0xb277e0 [0x3bf18ad0]>{value = +8, type = kCFNumberSInt32Type}
}
1 : <CFBasicHash 0xba0e50 [0x3bf18ad0]>{type = mutable dict, count = 5,
entries =>
0 : <CFString 0x3bf97334 [0x3bf18ad0]>{contents = "BlackBlock"} = <CFData 0xb9c550 [0x3bf18ad0]>{length = 2, capacity = 2, bytes = 0x8080}
2 : <CFString 0x3bf97344 [0x3bf18ad0]>{contents = "HorizontalSubsampling"} = <CFNumber 0xc0f720 [0x3bf18ad0]>{value = +2, type = kCFNumberSInt32Type}
4 : <CFString 0x3bf97324 [0x3bf18ad0]>{contents = "BitsPerBlock"} = <CFNumber 0xba0e80 [0x3bf18ad0]>{value = +16, type = kCFNumberSInt32Type}
5 : <CFString 0x3bf973b4 [0x3bf18ad0]>{contents = "FillExtendedPixelsCallback"} = <CFData 0xba16d0 [0x3bf18ad0]>{length = 12, capacity = 12, bytes = 0x00000000817bbb3100000000}
6 : <CFString 0x3bf97354 [0x3bf18ad0]>{contents = "VerticalSubsampling"} = <CFNumber 0xc0f720 [0x3bf18ad0]>{value = +2, type = kCFNumberSInt32Type}
}
)}
8 : <CFString 0x3bf97294 [0x3bf18ad0]>{contents = "PixelFormat"} = <CFNumber 0xb7acf0 [0x3bf18ad0]>{value = +875704438, type = kCFNumberSInt32Type}
12 : <CFString 0x3bf97174 [0x3bf18ad0]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
}
}
propagatedAttachments=<CFBasicHash 0x126e2130 [0x3bf18ad0]>{type = mutable dict, count = 4,
entries =>
1 : <CFString 0x3bf70edc [0x3bf18ad0]>{contents = "MetadataDictionary"} = <CFBasicHash 0xd5da1a0 [0x3bf18ad0]>{type = mutable dict, count = 7,
entries =>
0 : <CFString 0x3bf70f4c [0x3bf18ad0]>{contents = "SNR"} = <CFNumber 0xd5da1d0 [0x3bf18ad0]>{value = +33.11550123401803347178, type = kCFNumberFloat64Type}
2 : <CFString 0x3bf70ddc [0x3bf18ad0]>{contents = "sensorDGain"} = <CFNumber 0xd58def0 [0x3bf18ad0]>{value = +256, type = kCFNumberSInt32Type}
3 : <CFString 0x3bf70f3c [0x3bf18ad0]>{contents = "SensorID"} = <CFNumber 0x126f7b40 [0x3bf18ad0]>{value = +356, type = kCFNumberSInt32Type}
6 : <CFString 0x3bf7054c [0x3bf18ad0]>{contents = "ExposureTime"} = <CFNumber 0xd5d83d0 [0x3bf18ad0]>{value = +0.03332500000000000046, type = kCFNumberFloat64Type}
7 : <CFString 0x3bf70dec [0x3bf18ad0]>{contents = "ispDGain"} = <CFNumber 0xd54d620 [0x3bf18ad0]>{value = +273, type = kCFNumberSInt32Type}
11 : <CFString 0x3bf7017c [0x3bf18ad0]>{contents = "AGC"} = <CFNumber 0xd5e21f0 [0x3bf18ad0]>{value = +780, type = kCFNumberSInt32Type}
12 : <CFString 0x3bf7114c [0x3bf18ad0]>{contents = "AEAverage"} = <CFNumber 0xd5e27a0 [0x3bf18ad0]>{value = +126, type = kCFNumberSInt32Type}
}
3 : <CFString 0x3bf96f54 [0x3bf18ad0]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0xd5c34b0 [0x3bf18ad0]>{contents = "ITU_R_601_4"}
5 : <CFString 0x3bf96f94 [0x3bf18ad0]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x126bced0 [0x3bf18ad0]>{contents = "ITU_R_709_2"}
6 : <CFString 0x3bf96fd4 [0x3bf18ad0]>{contents = "CVImageBufferTransferFunction"} = <CFString 0xd58dfa0 [0x3bf18ad0]>{contents = "ITU_R_709_2"}
}
nonPropagatedAttachments=<CFBasicHash 0x126e2100 [0x3bf18ad0]>{type = mutable dict, count = 0,
entries =>
}
>
Bad output, front-facing camera.
Printing description of imageBuffer:
<CVPixelBuffer 0x12638980 width=352 height=288 pixelFormat=420v iosurface=0xd80e724 planes=2>
<Plane 0 width=352 height=288 bytesPerRow=384>
<Plane 1 width=176 height=144 bytesPerRow=384>
<attributes=<CFBasicHash 0x12638bb0 [0x3bf18ad0]>{type = immutable dict, count = 1,
entries =>
1 : <CFString 0x3bf971b4 [0x3bf18ad0]>{contents = "PixelFormatDescription"} = <CFBasicHash 0xb9fce0 [0x3bf18ad0]>{type = immutable dict, count = 7,
entries =>
0 : <CFString 0x3bf97164 [0x3bf18ad0]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
2 : <CFString 0x3bf97194 [0x3bf18ad0]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
3 : <CFString 0x3bf972c4 [0x3bf18ad0]>{contents = "ContainsAlpha"} = <CFBoolean 0x3bf18e88 [0x3bf18ad0]>{value = false}
5 : <CFString 0x3bf97184 [0x3bf18ad0]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
7 : <CFString 0x3bf972d4 [0x3bf18ad0]>{contents = "Planes"} = <CFArray 0xb24830 [0x3bf18ad0]>{type = mutable-small, count = 2, values = (
0 : <CFBasicHash 0xb99420 [0x3bf18ad0]>{type = mutable dict, count = 3,
entries =>
0 : <CFString 0x3bf973b4 [0x3bf18ad0]>{contents = "FillExtendedPixelsCallback"} = <CFData 0xba06a0 [0x3bf18ad0]>{length = 12, capacity = 12, bytes = 0x00000000917cbb3100000000}
1 : <CFString 0x3bf97334 [0x3bf18ad0]>{contents = "BlackBlock"} = <CFData 0xb9deb0 [0x3bf18ad0]>{length = 1, capacity = 1, bytes = 0x10}
2 : <CFString 0x3bf97324 [0x3bf18ad0]>{contents = "BitsPerBlock"} = <CFNumber 0xb277e0 [0x3bf18ad0]>{value = +8, type = kCFNumberSInt32Type}
}
1 : <CFBasicHash 0xba0e50 [0x3bf18ad0]>{type = mutable dict, count = 5,
entries =>
0 : <CFString 0x3bf97334 [0x3bf18ad0]>{contents = "BlackBlock"} = <CFData 0xb9c550 [0x3bf18ad0]>{length = 2, capacity = 2, bytes = 0x8080}
2 : <CFString 0x3bf97344 [0x3bf18ad0]>{contents = "HorizontalSubsampling"} = <CFNumber 0xc0f720 [0x3bf18ad0]>{value = +2, type = kCFNumberSInt32Type}
4 : <CFString 0x3bf97324 [0x3bf18ad0]>{contents = "BitsPerBlock"} = <CFNumber 0xba0e80 [0x3bf18ad0]>{value = +16, type = kCFNumberSInt32Type}
5 : <CFString 0x3bf973b4 [0x3bf18ad0]>{contents = "FillExtendedPixelsCallback"} = <CFData 0xba16d0 [0x3bf18ad0]>{length = 12, capacity = 12, bytes = 0x00000000817bbb3100000000}
6 : <CFString 0x3bf97354 [0x3bf18ad0]>{contents = "VerticalSubsampling"} = <CFNumber 0xc0f720 [0x3bf18ad0]>{value = +2, type = kCFNumberSInt32Type}
}
)}
8 : <CFString 0x3bf97294 [0x3bf18ad0]>{contents = "PixelFormat"} = <CFNumber 0xb7acf0 [0x3bf18ad0]>{value = +875704438, type = kCFNumberSInt32Type}
12 : <CFString 0x3bf97174 [0x3bf18ad0]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x3bf18e80 [0x3bf18ad0]>{value = true}
}
}
propagatedAttachments=<CFBasicHash 0x12638c10 [0x3bf18ad0]>{type = mutable dict, count = 4,
entries =>
1 : <CFString 0x3bf70edc [0x3bf18ad0]>{contents = "MetadataDictionary"} = <CFBasicHash 0x12638650 [0x3bf18ad0]>{type = mutable dict, count = 7,
entries =>
0 : <CFString 0x3bf70f4c [0x3bf18ad0]>{contents = "SNR"} = <CFNumber 0x126367e0 [0x3bf18ad0]>{value = +34.16280207318401096472, type = kCFNumberFloat64Type}
2 : <CFString 0x3bf70ddc [0x3bf18ad0]>{contents = "sensorDGain"} = <CFNumber 0x12633120 [0x3bf18ad0]>{value = +256, type = kCFNumberSInt32Type}
3 : <CFString 0x3bf70f3c [0x3bf18ad0]>{contents = "SensorID"} = <CFNumber 0x126360c0 [0x3bf18ad0]>{value = +38754, type = kCFNumberSInt32Type}
6 : <CFString 0x3bf7054c [0x3bf18ad0]>{contents = "ExposureTime"} = <CFNumber 0x12636440 [0x3bf18ad0]>{value = +0.02999900000000000136, type = kCFNumberFloat64Type}
7 : <CFString 0x3bf70dec [0x3bf18ad0]>{contents = "ispDGain"} = <CFNumber 0x12630f20 [0x3bf18ad0]>{value = +260, type = kCFNumberSInt32Type}
11 : <CFString 0x3bf7017c [0x3bf18ad0]>{contents = "AGC"} = <CFNumber 0xd580830 [0x3bf18ad0]>{value = +1803, type = kCFNumberSInt32Type}
12 : <CFString 0x3bf7114c [0x3bf18ad0]>{contents = "AEAverage"} = <CFNumber 0x12635ae0 [0x3bf18ad0]>{value = +176, type = kCFNumberSInt32Type}
}
3 : <CFString 0x3bf96f54 [0x3bf18ad0]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0x126383d0 [0x3bf18ad0]>{contents = "ITU_R_601_4"}
5 : <CFString 0x3bf96f94 [0x3bf18ad0]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x12632d90 [0x3bf18ad0]>{contents = "ITU_R_709_2"}
6 : <CFString 0x3bf96fd4 [0x3bf18ad0]>{contents = "CVImageBufferTransferFunction"} = <CFString 0x126372c0 [0x3bf18ad0]>{contents = "ITU_R_709_2"}
}
nonPropagatedAttachments=<CFBasicHash 0x12638be0 [0x3bf18ad0]>{type = mutable dict, count = 0,
entries =>
}
>
As Spectravideo328 has mentioned the byte per row isn't the same as width of the image. Hence you'll need to copy the valid data from the source layers to your destination buffer skipping the extra paddings. That means for each row (which is equal to the "height" of the image) copy the first "width" amount of bytes.
I have the following code :
a = cell(4,1);
a{1} = [5 3 0 0];
a{2} = [0 3 5 0];
a{3} = [1 3 0 0];
a{4} = [0 3 2 0];
arrayind = 2;
b = a(cellfun(#(x)x(arrayind) == 1,a));
b{:}
How can I achieve this when an IF statement is used :
if r>2
b = a(cellfun(#(x)x(arrayind) == (1 | 2 | 3),a));
end
Basically saying, find 1, if not there then 2, if not there then 3...
ismember could perhaps be what you are looking for.
Replacing the equality operator with ismember as follows:
a = cell(4,1);
a{1} = [5 3 0 0];
a{2} = [0 3 5 0];
a{3} = [1 3 0 0];
a{4} = [0 3 2 0];
arrayind = 1;
b = a(cellfun(#(x) ismember(x(arrayind), [1 5]), a));
would yield b = a([1, 3])
I was wondering how I need to prepare the data so it is ready for core-plot.
one line per year
dayOfYear in the x-axis
value on the y-axis
My x-axis has 366 points (Each day of the year). At the moment I have a dictionary that looks like this
2009 (year) = {
151 (dayofyear) = 5 (value);
192 = 25;
206 = 5;
234 = 20;
235 = 20;
255 = 20;
262 = 10;
276 = 10;
290 = 10;
298 = 7;
310 = 1;
338 = 3;
354 = 5;
362 = 5;
};
2010 = {
114 = 7;
119 = 3;
144 = 7;
17 = 5;
187 = 10;
198 = 7;
205 = 10;
212 = 10;
213 = 20;
215 = 5;
247 = 10;
248 = 10;
256 = 10;
262 = 7;
264 = 10;
277 = 10;
282 = 3;
284 = 7;
47 = 5;
75 = 7;
99 = 7;
};
2011 = {
260 = 10;
};
I think core-plot needs an array doesn't it? How would you pack this to be the most efficient?
The choice of data structure is completely up to you. You already have the data in a dictionary, so keep that. Implement the following method in your datasource:
-(NSNumber *)numberForPlot:(CPTPlot *)plot
field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index;
Assuming you have a separate plot for each year, use the plot parameter to select the appropriate year dictionary from the data dictionary. Use the fieldEnum parameter to determine whether the plot is asking for the x or y value and the index parameter to decide which value in the list to return.
For instance (assuming all values in the dictionaries are stored as NSNumber objects and you're using a scatter plot):
-(NSNumber *)numberForPlot:(CPTPlot *)plot
field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index
{
NSDictionary *year = // retrieve the year dictionary based on the plot parameter
NSDictionary *yearData = [year objectAtIndex:index];
NSNumber *num = nil;
switch ( fieldEnum ) {
case CPTScatterPlotFieldX:
num = [yearData objectForKey:#"dayofyear"];
break;
case CPTScatterPlotFieldY:
num = [yearData objectForKey:#"value"];
break;
default:
break;
}
return num;
}
I have actually changed the structure to this.
A dictionary with the year as the key and an array for each point containing the dayofyear and the value.
2009 = (
(354,5),
(338,3),
(234,20),
(298,7),
(192,25)
)
That way the implementation was very easy
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
return [[[self.data objectForKey:plot.identifier] objectAtIndex: index] objectAtIndex: fieldEnum];
}