Matlab code formatting similar to AStyle? [closed] - matlab

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Is there any tool similar to AStyle to format matlab code in m-files?

In recent versions of MATLAB, you can use the "Smart Indent" tool programmatically using the MATLAB Editor API.
As an example, say you want to fix indentation of all M-files contained in a specific directory:
%# gel list of m-files in a directory
BASE_DIR = 'c:\path\to\folder';
files = dir( fullfile(BASE_DIR,'*.m') );
files = {files.name};
for i=1:numel(files)
%# open file in editor, apply smart indentation, save and close
doc = matlab.desktop.editor.openDocument( fullfile(BASE_DIR,files{i}) );
doc.smartIndentContents;
doc.save;
doc.close;
end

Remember that you can select text in Matlab's editor and press Ctrl+I to auto-indent it. (Also , use Ctrl+A to select all the text.)

Related

How to name my averaging technique? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Suppose, I have a list of values {4, 10, 3, 6, 7, 15, 11}. The average of this number list is avg=8. Now I will select only those elements > avg, which are {10, 11, 15}. Now I am doing average again and selecting the elements bigger than their average. I believe this a helpful technique to get the top rated values from a list, I am not sure about the naming of this averaging technique. Can anybody help me with some name of this method?
Thanks in advance
How about using Averoveraging?
I'm not sure what your code looks like, but I'd imagine on one pass you are returning elements higher than the average? So I would name that method ElementsGreaterThanAverage.
If you're only always doing two passes, you could call it TopQuarterByAveraging or something.
You're computing the mean, then showing everything over it. Hence OverMean.

How many Distinct n variable boolean functions are there? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Since there are n variables wouldn't there be 2^n boolean functions?
For an n-ary boolean function, there are 2^n possible boolean inputs. Each input can generate
either "true" or "false" as the output. How many different ways can you arrange the 2^n true vs. false outputs?
If there are p possibilities for choice 1 and q possibilities for choice 2 then there are a total of p*q different ways of doing both.
It is trivial that this can be extended to n choices.
http://en.wikipedia.org/wiki/Rule_of_product
So, yeah, there would be 2^n boolean functions (as for each choice there are two alternatives).

Why languages do not allow multiple return values? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In languages like C which supports pointer operation, you can easily get multiple values from a procedure. But in languages like Java, it is a pain if you actually need to get multiple return values. (Using an object to wrap multiple values is bad)
In my experience, allowing multiple values returned can help improve software engineering--more flexible to organise procedure invocation, etc. But why there are so many languages that do no allow returning multiple values? I am interested to know the reasons. Thank you very much.
Could be because many of the designers of these languages have strong math backgrounds and in math a function can have multiple input parameters but (almost always) only a single output value.
Also, it keeps code understandable and standardized to some extent.

How do I write a generic function that takes a Number or some alphabets and display that in 7- bit segment display.? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I want to write a Digital Clock application in which I have a 7- bit segment display. I want to write a generic code for displaying all the input. I have a CGPath in which I have 1 line for each segment.
Now, how would I write a generic function for the above description?
Any help with some logic or code will be appreciated.
Thanks
Simplest would be a look-up table. You could do it with ten bytes. Assign one bit in the bytes to each segment. Pre-load the table with the hex values necessary to set the bits. Index the table with your digit 0-9. If you want to have additional combinations of segments then make the table larger -- typically these are set up to display an additional 6 "characters" (eg, A, b, C, d, E, and F), making the table conveniently 16 long.
But, for extra credit, do it with NAND gates.

Loading a file into MATLAB as it is? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm working on a telecommunications device simulator on MATLAB. I'm going to encode some digital data, modulate it, add some noise and attempt to demodulate it, see at what noise levels my data cannot be recovered anymore.
My problem is, I don't know how to import some crazy file to my workspace. It's not going to be txt or anything, just some file. How can I make MATLAB read the file in binary format or whatever it is called?
Try questions regarding to work with binary data in matlab
Working on Binary Data in Matlab
Read and write from/to a binary file in Matlab
Can you be more specific ??? Instead of specifying whatever format you could actually look at the extension and specify the extension.If it is a video then you can read it with mmreader(),if it is an image then you read it with imread().So please specify the extension of the file which you want to load into MATLAB.
H2H
-Harsha
It turns out I was using the right function with wrong parameters all along. I opened the file I wanted to open with fopen('filename') and used the number that function outputs in A=fread(thenumber). That returned an array of each and every byte in the file by their decimal values. I'm sure I'll be able to use this data for my project.
Thanks to everybody for their help!