Hauptinhalt

Results for


It is not uncommon for students to be assigned questions which they are required to complete "without using any built-in functions". There is not a great deal that can be programmed in MATLAB without using any built-in functions, but a little can be done -- but what, exactly is possible?
What a "built-in function" is, exactly, is open to interpretation. In the below, I refer instead to "publicly visible routines". Keywords (see below) are not publicly visible routines (they are "statements" or components of statements.) Any documented operation or call that invokes a MATLAB-supplied .m or .p or mex file or built-in library to do its work is a publicly visible routines. If you can use documented methods override the normal meaning of a statement or expression in practice by supplying alternate code, then the code probably involves publicly visible routines. If the language design is such that you could use documented methods to override the normal meaning of a statement or expression in theory (such as the behavior of adding two double, the code for which is in practice bundled into an internal MATLAB library), then I would still consider that a call to a publicly visible routine.
A MATLAB-supplied routine that is not documented, which is used for internal MATLAB purposes, could perhaps be held not to be a publicly visible routine, but it certainly would still be a "built-in function".
I exclude from the list any routine which there is no direct way to access, and is only used for internal purposes, such as the memory allocation routines.
This is what I have come up with:
  • the names defined as "keywords" do not in themselves involve function calls to publicly visible routines. These keywords currently include 'break', 'case', 'catch', 'classdef', 'continue', 'else', 'elseif', 'end', 'for', 'function', 'global', 'if', 'otherwise', 'parfor', 'persistent', 'return', 'spmd', 'switch', 'try', 'while'. There is no functional form of any of these: for example, one cannot use global(s) to declare the name contained in the variable "s" to be global. (However, you can define an "end" method; https://www.mathworks.com/help/matlab/matlab_oop/object-end-indexing.html )
  • scalar numeric double precision real-valued constants are handled at parse time, including unary plus and unary minus in front of them
  • scalar numeric double precision constants followed immediately by "i" or "j" create a complex-value constant at parse time, including unary plus and unary minus in front of them
  • whether a complete complex constant with real and imaginary part is handled at parse time is unknown
  • literal character vectors and string objects are handled at parse time
  • in sufficiently new versions, int64() and uint64() around an integer constant is handled at parse time. This was a change from previous versions which handled it at run time (after the integer had been converted to double precision...)
  • whether any other casts such as uint16() or logical() are now handled at parse time is unknown
  • assignment of a compete variable (no indexing, no substructure references, etc.) to a plain variable (no indexing, no substructure references, etc.) does not involve any function calls to publicly visible routines (unless I have overlooked a case involving objects)
  • "if" or "while" applied to a scalar logical constant or to a scalar logical variable does not involve any function calls to publicly visible routines. However, it is not known whether there is any method to construct a logical value without calling a MATLAB routine: "true" and "false" are MATLAB routines, not constants, and logical() of a numeric constant might be handled at run time
  • "for" in which the range is named as a scalar constant or scalar variable do not involve any function calls to publicly visible routines; for example, "for K = 5"
  • defining an anonymous function does not involve any function calls to publicly visible routines
I may have overlooked something due to shortage of chocolate in my bloodstream.
The language described above is not Turing complete, and is not "sufficiently powerful" for the purposes of the Church-Rosser Theorem of general-purpose computability. It is also not possible to do any arithmetic in it, as arithmetic must be reducible to the Peano Postulates, and those require at the very least the ability to compare a value for equality with 0, which in MATLAB would require a call to the MATLAB routine "eq".
What do you think of Cody? I'm interested in your comments
Hello all,
Please explain good MATLAB programming practice methods. It will help to the guys who are new to programming like me.
Previously I used
for i=1:10
after following some suggestions from this answers pages I learnt to use
for i1=1:100
This is the good way to write programs.
Like this, as a professional programmer, please mention some good programming practice techniques.
It will useful to all!
Capital letters are obtained by capitalizing the LaTeX command for the lowercase version. Capital letters in grey are exceptions which have no LaTeX commands. For example, to produce a capital chi simply type X (this also applies for the lowercase omicron).
When two versions of the lowercase letter are available, a var prefix can be added to obtain the second version. For example, the two versions of epsilon are \epsilon and \varepsilon.
--------------------------------------------------------------------------------------------------------------------------------------------------------
The code used to generate the table:
greeks = ...
{'ALPHA' 'A' '\alpha'
'BETA' 'B' '\beta'
'GAMMA' '\Gamma' '\gamma'
'DELTA' '\Delta' '\delta'
'EPSILON' 'E' {'\epsilon','\varepsilon'}
'ZETA' 'Z' '\zeta'
'ETA' 'H' '\eta'
'THETA' '\Theta' {'\theta','\vartheta'}
'IOTA' 'I' '\iota'
'KAPPA' 'K' '\kappa'
'LAMBDA' '\Lambda' '\lambda'
'MU' 'M' '\mu'
'NU' 'N' '\nu'
'XI' '\Xi' '\xi'
'OMICRON' 'O' 'o'
'PI' '\Pi' {'\pi','\varpi'}
'RHO' 'P' {'\rho','\varrho'}
'SIGMA' '\Sigma' {'\sigma','\varsigma'}
'TAU' 'T' '\tau'
'UPSILON' '\Upsilon' '\upsilon'
'PHI' '\Phi' {'\phi','\varphi'}
'CHI' 'X' '\chi'
'PSI' '\Psi' '\psi'
'OMEGA' '\Omega' '\omega'};
h = figure('units','pixels','pos',[300,100,620,620],'Color','w');
axes('units','pixels','pos',[10,10,600,600],'Xcol','w','Ycol','w',...
'Xtick',[],'Ytick',[],'Xlim',[0 6],'Ylim',[0,4]);
% Loop by column and row
for r = 1:4
for c = 1:6
el = (r-1)*6 + c;
% Title
text(c-0.5,5-r,greeks{el,1},'Fonts',14,'FontN','FixedWidth',...
'Hor','center','Ver','cap')
% Color cap latter in grey or black
if strcmp(greeks{el,2}(1),'\')
clr = [0, 0, 0];
else
clr = [0.65, 0.65, 0.65];
end
% Cap letter
text(c-0.5,4.87-r,['$\rm{' greeks{el,2} '}$'],'Fonts',40,...
'Hor','center','Ver','cap','Interp','Latex','Color',clr)
% Lowercase letter/s (if two variants)
if iscell(greeks{el,3})
text(c-0.75,4.48-r,['$' greeks{el,3}{1} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
text(c-0.25,4.48-r,['$' greeks{el,3}{2} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
% Latex command
text(c-0.5,4.3-r,['\' greeks{el,3}{1}],'Fonts',12,'FontN','FixedWidth',...
'Hor','center','Ver','base')
else
text(c-0.5,4.48-r,['$' greeks{el,3} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
text(c-0.5,4.3-r,['\' greeks{el,3}],'Fonts',12,'FontN','FixedWidth',...
'Hor','center','Ver','base')
end
end
end
% Print to pdf
export_fig greeks.pdf
The link to export_fig.
And here is the link to the pdf on scribd: http://www.scribd.com/doc/159011120/Greek-alphabet-in-latex
We all know that MATLAB is probably the best software for engineering purposes, I think it's a little expensive unless you have it for free on your school or place you work, please share your opinion about MATLAB cost, including toolboxes, student versions... is it that expensive?
[INDEX]
--------------------------------------------------------------------------------------------------------------------------------------
[MOTIVATION]
Why should we use markups in the body of our questions?
The answer is a question: which of the two versions is more likely to be understood in a glimpse and has more chances to be answered by our readers?
.
< Consider the following question >
I have a vector of weights W=[10,20,30,50,23434,1,2.4,2] and a matrix A=rand(100,8) and I would like to find the row-wise weighted sum of A. I am proceeding in the following way: B=zeros(size(A)); for c=1:numel(W) B(:,c)=A(:,c)*W(c); end B=sum(B,2); Somehow I get huge numbers can you please help?
.
< Now, consider its formatted version >
I have a vector of weights W = [10,20,30,50,23434,1,2.4,2] and a matrix A = rand(100,8) and I would like to find the row-wise weighted sum of A.
I am proceeding in the following way:
B = zeros(size(A));
for c = 1:numel(W)
B(:,c) = A(:,c)*W(c);
end
B = sum(B,2);
Somehow I get huge numbers can you please help?
--------------------------------------------------------------------------------------------------------------------------------------
[AKNOWLEDGMENTS]
In alphabetical order by nickname, thanks for their suggestions to:
Walter Roberson
--------------------------------------------------------------------------------------------------------------------------------------
[LOG]
  • 06 Aug 2011, 13:17 BST - created and added boldface.gif
  • 06 Aug 2011, 14:59 BST - added italic.gif
  • 06 Aug 2011, 18:58 BST - added index section
  • 07 Aug 2011, 00:03 BST - added code.gif and tutorial series section
  • 07 Aug 2011, 01:50 BST - added monospaced.gif, numlist.gif, bullist.gif and hyperlink.gif
  • 13 Aug 2011, 14:27 BST - added motivation section
  • 18 Aug 2011, 01:44 BST - added aknowledgments section and link to wish-list
--------------------------------------------------------------------------------------------------------------------------------------
[TUTORIAL Series]
Do not forget to read the Markup help (located on the top-right corner of the Body pane)
Vote on Wish-list for MATLAB Answer sections my post if you think that a tutorial section on top of Answers could be useful.
Doug Hull
Doug Hull
Last activity am 17 Feb. 2015

I think a lot about how to more effectively teach MATLAB, internally to new hires, but also through my blog.
How did you learn MATLAB, what knowledge of programming did you have coming into learning MATLAB? When did you learn it is important also as the resources available have expanded radically in the last 15 years.
Answers from new users who are just beginning down this path are of particular interest, as those are who we can help the most.
Now, I am still a novice when it comes to programming. I believe MATLAB is definitely a great programming tool, one that I can play with, particularly, when I have free time.
I would love to hear from all answerers, what are the ways that can make one proficient in this field?
Don't be shy, what was your matlab learning curve, how many years or months, what were the difficulties to begin with.
I think that the answers would be most valuable for new users, maybe you can also tell us the tricks that allowed you to master some parts or all matlab.
Now it's your turn...
Jan
Jan
Last activity am 20 Sep. 2024

Which Matlab related forums and newsgroups do you use beside MATLAB Answers? Which languages do they use? Which advantages and unique features do they have?
Do you think that these forums complement or compete against MathWorks and its communication platform?
Actually all answers are accepted.
O.k., admit it. Who has done this (or something that resulted in the same loss of info) before?
>> laster
??? Undefined function or variable 'laster'.
>> lasterr
ans =
Undefined function or variable 'laster'.
D'Oh! I need a ERRORBEFORELASTERR function.
What's one of your dumb MATLAB mistakes?
Are there parts of MATLAB that could disappear as far as you were concerned, things you don't need or which were "bad ideas" or which cause more trouble than they are worth in your experience?
One suggestion per answer please, so we can see how other people feel about the same matters.
I use MATLAB most days (when I'm at work!). It makes my life easier, for many reasons, which is why I like it.
What are the reasons you like it (assuming you do), and why?
I love MATLAB. It is so quick and easy to write software to do what you want. It has excellent debugging and profiling tools. It is cross platform, making code easy to share (assuming the other people have forked out for the not-so-cheap license). It has interfaces to other software.
However, there are some things about it that irk me. I'd like to hear from other people what things annoy them about MATLAB.
---------------------------------
Because this thread has become so large it is slow to load and navigate. Please post new answers in the second thread.
---------------------------------
amit jain
amit jain
Last activity am 2 Jun. 2023

What is the best way to learn MATLAB at home without a tutor?
As asked by Vieniava in "How to make a list of user's reputation?", some of us came up with interesting ideas on how to fill an updated list with the reputation scores of the contributors to Answers.
I took the initiative to compile a public list of users with meta info:
  • position (desc ordering by reputation)
  • id
  • nickname (truncated to fit the page)
  • reputation
  • # of comments
  • # of questions asked
  • % accept rate
  • # of posts answered
  • # of accepted answers
The code used to compile the list is available at the bottom.
EDIT
TMW team implemented a page with the metascores: http://www.mathworks.com/matlabcentral/answers/contributors
Please refer to it and congrats to the team!
Use this function to retrieve info from the link above:
function [metainfo, elapsedTime] = metainfo(type,order)
% METAINFO - Retrieve metainfo on contributors to www.matworks.com/.../answers
%
% METAINFO Retrieve data sorted by reputation in descending order
%
% METAINFO(TYPE,ORDER) Specify TYPE and sorting ORDER as
% type : 'reputation'
% 'questions'
% 'answered'
% 'accepted'
%
% order: 'asc'
% 'desc'
%
% Examples:
%
% % Standard call (rep, disc)
% info = metainfo;
%
% % Sort by question answered in descending order
% info = metainfo('an','d');
%
% See also: URLREAD, REGEXP
% Author: Oleg Komarov (oleg.komarov@hotmail.it)
% Tested on R14SP3 (7.1) and on R2009b. In-between compatibility is assumed.
% 28 feb 2011 - Created
tic
% Check # inputs
error(nargchk(0,2,nargin))
% Retrieve inputs
if nargin == 0
type = 'reputation';
order = 'desc';
end
if ~exist(type,'var')
sortTypes = {'reputation','questions','answered','accepted'};
type = sortTypes{strncmp(type,sortTypes,numel(type))};
order = 'desc';
end
if ~exist(order,'var')
orderTypes = {'asc','desc'};
type = orderTypes{strncmp(order,orderTypes,numel(order))};
end
% Build url string
url = ['http://www.mathworks.com/matlabcentral/answers/contributors?'...
'dir=' order '&sort=' type '&page='];
% First read
[page, ok] = urlread([url '1']);
% Catch number of pages to read
if ok
totcon = regexp(page,'>1 - 50 of (\d+)','tokens');
totcon = dataread('string',totcon{1}{1},'%d');
nPages = ceil(totcon/50);
else
error('Cannot read ".../contributors?page=1"')
end
% Loop over contributors pages
metainfo = cell(totcon,7);
metainfo(1:end,1) = num2cell(1:size(metainfo,1));
for p = 1:nPages
if ok
endpos = 50*p;
% Id, Rep
expr = '><a href="\/matlabcentral\/answers\/contributors\/(\d+)';
data = regexp(page, expr,'tokens');
if 50*p > totcon; endpos = 50*(p-1)+numel(data); end
metainfo(1+(p-1)*50:endpos,2) = [data{:}];
% Nickname
expr = ['"Reputation: (\d+)">([\w\ ' reshape([repmat(92,1,137);33:59,61:64,91:97,123:126,161:255],1,[]) ']+)</a></h2>'];
data = regexp(page, expr,'tokens');
metainfo(1+(p-1)*50:endpos,[4,3]) = cat(1,data{:});
% Qcount, Ans, Acc
data = regexp(page, '<span >(\d+)</span>[A-z<>"-\s\/]+','tokens');
metainfo(1+(p-1)*50:endpos,5:7) = reshape(cat(1,data{:}),3,[]).';
else
error('Metainfo import stopped. \nCannot read ".../contributors?page=%d"',p)
end
[page, ok] = urlread([url sprintf('%d',p+1)]);
end
% Convert to doubles
metainfo(:,[2,4:7]) = cellfun(@str2double,metainfo(:,[2,4:7]),'un',false);
elapsedTime = toc;