Alternative of the imageDatastore function - matlab

I have been going through a tutorial of deep learning in MATLAB. I tried to execute the following code
rootFolder = 'E:/Data Science and Machine Learning Stuff/DataSets/scene_categories';
categories = {'bedroom' , 'CALsuburb' , 'industrial' , 'kitchen' , 'livingroom','PARoffice','store'};
imds = imageDatastore(fullfile(rootFolder, categories),'LabelSource', 'foldernames');
tbl = countEachLabel(imds)
Executing the above code generates the following error:
Undefined function or variable 'imageDatastore'.
After doing a lot of research about the error I finally came to know that the function imageDatastore is introduced in R2015b.
My current MATLAB release is R2015a, so I do not have access to this function. I have also tried the datastore function that is present in this release (R2015a) but have had no luck.
Can anyone help in writing an alternative code for the imageDatastore function that performs the same function as imageDatastore; or can some tell me how to use the datastore function for this task.

Related

unable to interface my c++ application with MATLAB

I have written a program in c++11. My intention is to use MATLAB environment for plotting.
So, I followed these two links to have some idea:MATLAB_Build C++ Engine programs and c++ start MATLAB session. (There must be other ways to interface MATLAB and c++. But I want to know where is my fault before trying other ones)
As those above links have suggested I built my project accordingly using visual studio '17. The initial errors that I found was, my application could not locate the following .dll files libMatlabEngine.dll, libMatlabdataArray.lib.
So, I moved my .dlls to the executable location as suggested here. But after then my code is throwing the following error: 0xC0000005: Access violation executing location 0x0000000000000000.
Below is the piece of code that I'm trying. I guess it's the startMATLAB() which is returning a NULL pointer and the code is failing for that. But I can't figure out what's the reason.
Appreciate your help.
//Start the MATLAB engine
using namespace matlab::engine;
using namespace matlab::data;
unique_ptr<MATLABEngine> matlabptr = startMATLAB();
//Cretae a matlab array factory
ArrayFactory factory;
auto inputArray = factory.createArray({ 1, 6 }, cppData.cbegin(), cppData.cend());
auto time_array = factory.createArray({ 1, 6 }, time.cbegin(), time.cend());
matlabptr->setVariable(convertUTF8StringToUTF16String("data"), move(inputArray));
matlabptr->setVariable(convertUTF8StringToUTF16String("time"), move(time_array));
matlabptr->eval(convertUTF8StringToUTF16String("plot(time, data)"));

Unable to run code for DSP-SIFT in MATLAB

So, I got the code for DSP-SIFT from the original works of the author in the form of a toolbox. When I followed the instructions and tried to get it to run in MATLAB :
>> dsp_setup
>> dsp_mosaic
Undefined function 'vl_usift' for input arguments of type 'single'.
Error in vl_dspsift (line 50)
frames = vl_usift(im);
Error in dsp_mosaic (line 68)
[f1, d1] = vl_dspsift(im1g, opt);
After Googling this error(I am new to MATLAB), I found a solution saying that maybe my function cannot be recognised by MATLAB, so I need to add the containing folder to the MATLAB search path, which I tried doing:
>> which vl_usift -all
'vl_usift' not found.
>> addpath ('/home/dsp_toolbox_v0.0.2/dsp_toolbox_v0.0.2/toolbox/sift/')
Howver, I get the same error when trying to run the code.
I can add the code if it helps, but I do need advice on how to proceed from here.
Thanks
So, after a few hours of searching around, I finally came across the problem, there were a few lines commented in the setup file which I had to uncomment. Simple and frustrating.
Thanks!

What is the full command for gdal_calc in ipython?

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

how to connect or load file.dll to matlab?

I want through matlab tutorial but I did not understand it clearly.
Could anyone can explain to me step by step how to load and call .dll functions in matlab?
I tried to use loadlibrary function but I get and error, if anyone can tell we where to put the .dll file and the .h file?
I don't do this often, but i usually do something like:
fullpathToHeader = 'c:\full\path\to\a\header.h';
fullpathToDll = 'c:\full\path\to\a\libraty.dll';
loadlibrary(fullpathToDll, fullpathToHeader);
Then if that works, you can call library functions as:
[outArg1, outArg2, ...] = calllib('library','function',inArg1, inArg2, ...)
See the following link, which contains some problems I encountered and overcame, when trying to load a dll into matlab:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/341602

Matlab editor issue, a bug?

I am having this problem that when I run the below written code in the main screen matlab does'nt give me a problem.
However if i write it in the editor then it complains that it is invalid syntax.
Can you tell me what am i doing wrong or is it a bug?
Ques1 = { #(data) mean(data) #(data) std(data) };
mean = Ques1 {1} (data(:,1)) # runs perfectly on the main compiler screen
On my editor page the compilers complains on the = sign that a possible bracket is missing. However I do not understand why it works on the matlab line by line compiler !!
Those two lines of code are absolutely correct. Somewhere in you code you have forgotten an open left bracket e.g. [ , { , (
EDIT Now I understand what g24l was saying! Yes, that is likely the culprit of your problem.
Not sure what version of matlab you're using but when I run a very simple script:
data = kron(1:25,transpose(1:25)); % very simple 2D matrix of data;
Ques1 = { #(data) mean(data) #(data) std(data) };
mean1 = Ques1 {1} (data(:,1)) % runs perfectly on the main compiler screen
It works perfectly on R2007B and R2009B, are you using an older or newer version? I suspect there is some other issue creeping up in your script. Also, as a matter of following Mathworks recommended programming procedures, I would encourage you not to name a variable or function the same name as another variable or function. In this instance I'm referring to mean = .... It's easy to get this stuff mixed up and then have nasty problems. If you need more help, please feel free to post more of your script. Hope this helps!
I don't have access to Matlab at the moment so I can't test this out, but your syntax doesn't look right to me. Try this:
Ques1 = {#(data)mean, #(data)std};
mean = Ques1{1}(data(:,1))
If you run it your way in your debugger, how many elements does it say are in your cell array?