1.0

1.0 | 2 ratings Rate this file 2 Downloads (last 30 days) File Size: 1.25 KB File ID: #21575

Discrete matrix distribution and it's parameters for educational purpose.

by Mathan Chandran

 

25 Sep 2008 (Updated 25 Sep 2008)

Various parameters of 2D discrete variable

| Watch this File

File Information
Description

Example - dismat(50,5,6) creates 5x6 probability matrix and gives various parameters. Freshers can see and appreciate the work load in the computation. oo.dat will be created with results.

Required Products Statistics Toolbox
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
26 Sep 2008 Jos x@y.z

Complete lack of comments and help, so where is the educational value? Also, do not zip a single m-file.

26 Sep 2008 John D'Errico

No useful help to anyone in the world. What does this do? Why does it do it? How will it help anyone?

No H1 line. No error checking. Virtually the only internal comment line is this:

%success--------------------------------------------------------------

Will that be of any help to someone who is reading the code? No.

Any "freshers" who bother to look at this will be wasting their time.

How about the coding style? I'm sorry, but it is MISERABLE. Here is a representative piece of it. I could swear that the author learned to code from Marco.

   y1 = unidrnd(a,n1,n2);
    y2 = sum(sum(y1));
    y3 = sum(sum(y1'));
    y4 = y1/y2;
   r = unidrnd(100,1,n2);
   r = sort(r);
   c = unidrnd(100,n1,1);
   c = sort(c);
   y5 = [r;y4];
   c = [0;c];
   y6 = [c,y5];
  y7 = sum(y4')';
  y8 = sum(y4);
  y7 = [0;y7];
  y8 = [0,y8,1];
  y9 = [y6,y7];
  yy = [y9;y8];
  y100 =yy;

This is NOT how you want to teach anybody to program, nor what they should learn from. If I could rate this a -1, I would do so.

26 Sep 2008 John D'Errico

I was thinking, I should explain why the code fragment in my previous review is so poor.

1. There are NO comments. My recommendation is that a good programmer in Matlab should aim for somewhere near to one line of comment for every line of code. You don't need to hit that goal all of the time, but its not a bad goal to have. Why is this a good goal? A matrix language like Matlab can be a dense one. You can pack a lot of functionality into a single line of code. So your comments should explain what has been done, and why. Those comments should help you to debug your code a year from now if you learn about a bug, or if you need to make a change.

2. The variable names are numerically sequential. DON'T DO THIS. Instead, use intelligent, mnemonic names. Intelligently chosen names are self documenting. They help you to read the code, to understand it.

I could probably go on with this, but the points above are a good start. As it is, this small code fragment is the code from hell. If you are a student or a novice programmer and you see code like this, do yourself a favor and run like crazy in the other direction.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
statistics Mathan Chandran 22 Oct 2008 10:21:36
probability Mathan Chandran 22 Oct 2008 10:21:36
discrete Mathan Chandran 22 Oct 2008 10:21:36
2d Mathan Chandran 22 Oct 2008 10:21:36
random Mathan Chandran 22 Oct 2008 10:21:36
statistics and probability Mathan Chandran 22 Oct 2008 10:21:36
variable Mathan Chandran 22 Oct 2008 10:21:36
2d Cristina McIntire 10 Nov 2008 10:55:35
probability Cristina McIntire 10 Nov 2008 10:55:39
statistics Cristina McIntire 10 Nov 2008 10:55:42

Contact us at files@mathworks.com