I use AppDesigner inMATLAB to show photos with changed RGB. But there is the problem with character of the photo.
When I switch on my own fuction "changeRGB", finally "choosenImage" has 20bytes, class "char" and size(1x10). OK!
There is no problem in using the "function OpenButtonValueChanged". OK!
There is the problem with "function UploadButtonPushed". OK!
ABOUT THE PROBLEM:
When I click button which callback is "function UploadButtonPushed" I get the error:
"Error using imread>parse_inputs (line 502)
The file name or URL argument must be a character
vector or string scalar."
"Error in imread (line 342)
[source, fmt_s, extraArgs, was_cached_fmt_used] =
parse_inputs(cached_fmt, varargin{:});"
WHY?
Because in the "function UploadButtonPushed" my choosenImage has 1977624bytes, class "uint8" and size(681x968x3). So it's too bug for "imread".
WHAT I TRIED:
When in "function OpenButtonValueChanged" I convert a photo, adding "char": (myimage = char(app.clickedImage)); the class of the photo is changing from uint8 to char but the size.
When I use "num2cell", the claas of the photo is changing on "cell" but size and number of bytes are the same- so big. And I get the Error: "Error using imread>parse_inputs (line 502) The file name or URL argument must be a character vector or string scalar."
In my own function "changeRGB" I used "imread(image)" and here is the problem with the size of the photo. Do you know how to get the correct one?
%my own properties in AppDesigner- to use them in different functions
properties (Access = public)
clickedImage;
addR = 1;
addG = 1;
addB = 1;
end
%first function in AppDeesigner
function OpenButtonValueChanged(app, event)
value = app.OpenButton.Value;
[file, howManyFiles] = chooseImagesFromComputer; %myown function
%I load 3 images which are showed as miniatures
myFile1 = imread(file{1});
imshow(myFile1, 'Parent', app.UIAxes1_1);
myFile2 = imread(file{2});
imshow(myFile2, 'Parent', app.UIAxes1_2);
myFile3 = imread(file{3});
imshow(myFile3, 'Parent', app.UIAxes1_3);
%take values of changed RGB from the slider
app.addR = app.SliderR.Value
app.addG = app.SliderG.Value
app.addB = app.SliderB.Value
%work only on one image to change its colors. app.clickedImage, app.addR, app.addG, app.addB are properties at the beginning of the code
app.clickedImage = file{1};
app.clickedImage = changeRGB(app.clickedImage,app.addR,app.addG,app.addB); %changeRGB- my own function- here is the problem. I add it bottom
imshow(app.clickedImage,'Parent',app.UIAxesMain);
end
%second function in AppDesigner
%here is the button to upload color of the photo
function UploadButtonPushed(app, event)
myimage = app.clickedImage;
myimage = changeRGB(myimage,app.addR,app.addG,app.addB);
imshow(myimage);
end
%here is my own function in matlab, not in AppDesigner, which makes problem:
function [changedImage] = changeRGB(choosenImage, addR, addG, addB)
whos
loadedImage = imread(choosenImage);
R = loadedImage(:,:,1); %extract one of the color channels
G = loadedImage(:,:,2);
B = loadedImage(:,:,3);
RBG = cat(3,R,G,B);
R_adj2 = R + addR;
G_adj2 = G + addG;
B_adj2 = B + addB;
changedImage = cat(3,R_adj2,G_adj2,B_adj2);
end
First, you make unnecessary operations in changeRGB
function [changedImage] = changeRGB(choosenImage, addR, addG, addB)
loadedImage = imread(choosenImage);
loadedImage = bsxfun(#sum, loadedImage, reshape([addR, addG, addB], [1 1 3]);
end
Then this function return an array (the modified image) so in UploadButtonPushed(app, event) when you run myimage = app.clickedImage;, you are passing the modified array instead of the image path, that you set here app.clickedImage = changeRGB(app.clickedImage,app.addR,app.addG,app.addB);
So you have to change the design of your variables, because app.clickedImage is saving either the image path, or the image itself. Consider having 2 different variables.
A good advice also is to use matlab debugger which is really good help to find the source of this kind of problems.
I have created one array like below
var childControllers = NSArray()
childControllers = NSArray(objects: OBDPage1, OBDPage2, OBDPage3, OBDPage4)
self.loadScrollView(page: 0)// calling method
now I want to use array object like below
func loadScrollView(page: Int){ // method
if page >= childControllers.count {
return
}
// replace the placeholder if necessary
let controller: OBDPage1ViewController? = childControllers[page]
}
but I am getting below error
Swift-CarAssist/Swift-CarAssist/OBDCarMonitorDeatilViewController.swift:90:67: Cannot convert value of type 'Any' to specified type 'OBDPage1ViewController?'
can any one tell me where I am going wrong as I am new to swift.
Thanks in advance.
Priyanka
Working in Swift you should use Swift Array rather than NSArray
var childControllers = [UIViewController]()
childControllers = [OBDPage1,OBDPage2,OBDPage3,OBDPage4]
self.loadScrollView(page: 0)// calling method
then
func loadScrollView(page: Int){ // method
if page >= childControllers.count {
return
}
// replace the placeholder if necessary
let controller = childControllers[page] as? OBDPage1ViewController
}
Try this:
let controller = childControllers[page] as! OBDPage1ViewController
You have to explicitly cast the array value as an OBDPage1ViewController, otherwise it is just of type Any.
Edit:
To be more safe, it is recommended that you perform this using if-let conditional binding.
if let controller = childControllers[page] as? OBDPage1ViewController {
//do something
}
Trying to get my question answered (Retrieve Boolean array from Firebase) I am trying to solve the question by myself. I think I am almost done but 1 thing is bugging me. I want to retrieve a boolean array and store it in a boolean array in my app.
This is what I got:
if snapshot.key == "whatAchievementsunlocked"
{
whatAchievementsUnlocked.removeAll()
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for x in snapshots
{
print(x.value!) //prints 0
var valueForIndexX = x.value as! Int //crash
print(valueForIndexX)
if valueForIndexX == 0
{
whatAchievementsUnlocked.append(false)
}
else
{
whatAchievementsUnlocked.append(true)
}
}
}
}
Why would it crash there? If I use as?, the output would be nil. I also tried to use var valueForIndexX = Int(x.value!) But that gives me an error: Cannot invoke initializer for type Int with an argument list of type (Any). The output of x.value! is clearly an Int, why would this result in an error? The debug just shows "(lldb)". What am I doing wrong?\
Can someone tell me why this is failing at
row.add(rs.getString(i))
rs=pst.executeQuery();
while(rs.next())
{
ObservableList<XYChart.Series<Date, Number>> row = FXCollections.observableArrayList();
for(int i =1; i<=rs.getMetaData().getColumnCount(); i++)
{
row.add(rs.getString(i));
}
}
The error i get is
no suitable method found for add(String)
method Collection.add(Series) is not applicable
(argument mismatch; String cannot be converted to Series)
method List.add(Series) is not applicable
(argument mismatch; String cannot be converted to Series)
I'm not sure what I should change.
I am unsure why I get this error when I run my program a certain way.
2014-05-15 16:19:28.932 Puzzle[1002:f803] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInternalInconsistencyException> -[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object
I have an NSMutableArray called 'levelsCompleteArray' that I am trying to cycle through to see when the first NO, (or 0) appears and to set that iteration to a variable called 'picIndex'. If there are no YES's in the array, then the program works fine. When there is one in the next iteration, however, I get the message posted above. Does anyone know why? Code below:
[levelsCompleteArray replaceObjectAtIndex:picIndex withObject:[NSNumber numberWithBool:YES]];
BOOL wonLevel=NO;
int i=picIndex;
while (wonLevel==NO)
{
BOOL status =[[levelsCompleteArray objectAtIndex:i] boolValue];
if (status==1)
{
i=i+1;
if(i==3)
{
picIndex=0;
wonLevel=YES;
}
}
else
{
picIndex=i;
wonLevel=YES;
}
}
It looks like levelsCompleteArray is an NSArray which is immutatable. To turn it into a mutable array try this:
NSMutableArray* mutableLevelsCompleteArray = [[NSMutableArray alloc] initWithArray:levelsCompleteArray];