How can i convert this simple program from Matlab into visual basic

x_clean(1)=0;
y_c(1)=initial;
for t_c=1:intervals
x_clean(t_c+1)=Pd*t_c;
end
[m,n]=size(x_clean);
y_cc=ones(m,n);
y_clean=y_c*y_cc;
%%ALSO HOW CAN CHANGE y(end) VALUE INTO VISUAL BASIC
Thank you for your kind support

回答 (2 件)

Prajit T R
Prajit T R 2018 年 4 月 9 日

0 投票

Hi Musa
What you can do is to make a DLL (mex) file from your MATLAB script and call that in VB.
Another approach is to call your written MATLAB function from VB. See this link: Call MATLAB function from VB
To rewrite the code entirely in Visual Basic, you can refer the following ML Answers link: Converting MATLAB code to VB code
Cheers

2 件のコメント

Walter Roberson
Walter Roberson 2018 年 4 月 9 日
Hah, I had forgotten I wrote that!
Gali Musa
Gali Musa 2018 年 4 月 9 日
Dear Sir,
Actually the reason for the conversion is that i want to use a software that is written in Visual Basic, so i have to convert my Matlab code to do that. i have read on the VB example but having difficulty in using loops and how to convert y(end) into VB. i think the last option should be the best solution. can i write VB without using Console.WriteLine and Console.ReadLine.
How can i convert y(end) into VB.
Thank you for your kind support

サインインしてコメントする。

Guillaume
Guillaume 2018 年 4 月 9 日

0 投票

y(end) is simply the last element of the array, so you simply have to replace the end by the index of the last element of the array whatever that is. Since in VB all arrays have a fixed size you know what that index is.

6 件のコメント

Gali Musa
Gali Musa 2018 年 4 月 9 日
I actually used y(end) for many cases (in optimisation) which can represent the last value for all the engines, if i use the last index of the element then its going to be an issue for the other engines.
Guillaume
Guillaume 2018 年 4 月 9 日
if i use the last index of the element then its going to be an issue
y(end) means exactly that in matlab: the last index. Nothing else. So I don't understand what could be an issue.
Whenever you write y(end) in matlab you can rewrite it as y(numel(y)) and the code will behave the same.
Gali Musa
Gali Musa 2018 年 4 月 9 日
I don't have any issue in Matlab everything is working perfectly... what i mean is changing that into visual basic...........
Guillaume
Guillaume 2018 年 4 月 9 日
Yes, I understood. I still don't see the problem you'd have in converting matlab's y(end) into VB code. That bit is easy it's just y(numberofelements), e.g. if the matlab code is:
y = zeros(1, 100);
%...
y(end) = 10;
The VB code is
Dim y(100) as Double
' ...
y(100) = 10;
Of course, if the numbers of elements in the matlab arrays is variable, then you can't use an array in VB (or at least, you shouldn't) but that's a different and bigger problem than the y(end).
Guillaume
Guillaume 2018 年 4 月 10 日
As I wrote
... or at least, you shouldn't ...
Yes, you can ReDim an array in VB, it's just as bad as growing an array in matlab. There are much better data types available in .Net if you want a dynamic array. Typically, you'll use a List.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2018 年 4 月 6 日

コメント済み:

2018 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by