run matlab script that process series of images in visual studio(c# language)?

1 次查看(过去 30 天)
using following Matlab code I have successfully load the images in folder (location:F:\anuradha) but when it is run through visual studio (c# language) results were not obtained. can anyone help me????
%code_01
filePattern1 = fullfile('F:\anuradha\', '*.jpg');
imagefiles1 = dir(filePattern1);
it should be mention here I have create object in C# and the matlab script is passed in to string the following code gives more explanation
string mScript;
MLApp.MLApp matlab = new MLApp.MLApp();
private void loadMScript_segment()
{
System.IO.StreamReader myFile =
new System.IO.StreamReader("F:\\anuradha\\resizeing.m");
mScript = myFile.ReadToEnd();
myFile.Close();
}
private void buttonsgmnt_Click(object sender, EventArgs e)
{
loadMScript_segment();
matlab.Execute(mScript);
}
here resizeing.m is the matlab script which is included * _ code_01_* mention above
here it is not the case of execution pattern. it gives error at the matlab script, which is mention below.
%resizeing.m
filePattern1 = fullfile('F:\anuradha\', '*.jpg');
imagefiles1 = dir(filePattern1);
imagefiles1 = dir(filePattern1);
nfiles1 = length(imagefiles1);
for jj=1:nfiles1
currentfilename1 = imagefiles1(jj).name;
currentimage1 = imread(currentfilename1);
images{jj} = currentimage1;
b = currentimage1;
figure;
imshow(b);
hold on;
end
according to the above code it should be display all image inside the folder after run the c# code

回答(1 个)

Walter Roberson
Walter Roberson 2015-11-14
Why not just simply execute
matlab.Execute("run F:\\anuradha\\resizeing.m")
  3 个评论
Image Analyst
Image Analyst 2015-11-14
So it fails in the MATLAB code, not the C code. Well, you forgot to post the MATLAB error text. Please copy and paste all the error code that you see. Can you run the MATLAB code entirely from within MATLAB successfully?
Walter Roberson
Walter Roberson 2015-11-14
You did not take into account that you might not be cd'd to the correct directory.
%resizeing.m
projectdir = 'F:\anuradha';
filePattern1 = fullfile(projectdir, '*.jpg');
imagefiles1 = dir(filePattern1);
nfiles1 = length(imagefiles1);
for jj=1:nfiles1
currentfilename1 = fullfile(projectdir, imagefiles1(jj).name);
currentimage1 = imread(currentfilename1);
images{jj} = currentimage1;
b = currentimage1;
figure;
imshow(b);
hold on;
end

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by