what is the line of code mean?

this line from earlier version of Matlab :
c=Table[If[t==1, 0.7071, 1], {t,1,n}]; in the newer version this line indicate this error:
c=Table[If(t==1, 0.7071, 1), {t,1,n}];
|
Error: Unbalanced or unexpected parenthesis or bracket.
plz what is problem exactly? note: I new user in matlab.

2 Comments

Azzi Abdelmalek
Azzi Abdelmalek on 1 Jan 2013
Edited: Azzi Abdelmalek on 1 Jan 2013
What are If , t and n in your code?
Azzi Abdelmalek
Azzi Abdelmalek on 1 Jan 2013
Edited: Azzi Abdelmalek on 1 Jan 2013
This is not a Matlab code, and you have not provided enough data. What is Table?

Sign in to comment.

Answers (2)

That is not MATLAB code. An if with three arguments looks like visual basic. But if Table is an array, it needs parentheses, not brackets. Or if Table is a scalar and it's multiplying a vector, then the vector has to be after a *, like this:
c = Table .* [1 42 73 999];
And it that's an if, it can't have a capital I. I think you can have an array called "If" because MATLAB is case sensitive. But then you have braces after that which means If would be a cell array. But if it were a cell array, you couldn't have a comma after the ",1)" and before the "{t,1,n}".
And it it is an "if" instead of an "If" then you can't have an if statement as an element of an array.
So, this is so messed up in several ways. It's so messed up I can't even try to guess what it was trying to do.

3 Comments

this code from data compression book and its Experiments with the One-Dimensional DCT and the complete code is:
n=8;
p={12.,10.,8.,10.,12.,10.,8.,11.};
c=Table[If[t==1, 0.7071, 1], {t,1,n}];
dct[i_]:=Sqrt[2/n]c[[i+1]]Sum[p[[t+1]]Cos[(2t+1)i Pi/16],{t,0,n-1}];
q=Table[dct[i],{i,0,n-1}] (* use precise DCT coefficients *)
q={28,0,0,2,3,-2,0,0}; (* or use quantized DCT coefficients *)
idct[t_]:=Sqrt[2/n]Sum[c[[j+1]]q[[j+1]]Cos[(2t+1)j Pi/16],{j,0,n-1}];
ip=Table[idct[t],{t,0,n-1}]
but indicate above error.
Again, doesn't look like MATLAB code to me, at least not since I've been using it. For example I don't believe there is a ":=" operator in MATLAB, nor are there functions called Sqrt() and Sum() (MATLAB has only lower case versions of those and MATLAB is case sensitive). Perhaps someone will recognize what language it's in.
thanks for your answers

Sign in to comment.

Walter Roberson
Walter Roberson on 1 Jan 2013
The code shown is Mathematica code, not MATLAB code.

Asked:

on 1 Jan 2013

Community Treasure Hunt

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

Start Hunting!