How to access matrix alphabetically [duplicate] - matlab

This question already has answers here:
How to compute word scores in Scrabble using MATLAB
(2 answers)
Closed 7 years ago.
I'm new to matlab ... I simply would like to convert letter to numbers such that:
A=1
B=2
C=3
all my numbers are capital case. Off course, I could define constant for each char, but is there a shorter way?
Thanks!

See the char function. You can give it an integer argument.
http://www.mathworks.com/help/matlab/ref/char.html

Related

why ncread function in matlab reduce floating point numbers count? [duplicate]

This question already has answers here:
How to store more than 4 decimal places in an array in MATLAB
(2 answers)
Closed 5 years ago.
i have code below in matlab:
converted = ncread(this_file, 'U');
disp(converted(50,10,20));
and the result is:
-0.1561
actually the number is -0.15617890 but this code changes the the number of floating numbers. why?
MATLAB displays only 4 digits after the decimal point by default. You can use format to display more digits:
format long
converted = ncread(this_file, 'U');
disp(converted(50,10,20));

Extract data and rename each iteration in loop [duplicate]

This question already has answers here:
How to automatically create variables which are column extracts from a matrix
(4 answers)
MATLAB - Need to split a Matrix into column variables with names sourced from another matrix?
(3 answers)
Closed 5 years ago.
I have created a color map:
Color map=jet(40)
From this I want to use a loop to extract each row of the colormap as 40 separate matrix (vector) with the title rgb1-rgb40. How to do this?
You can use eval to execute a dynamically created string as follow:
map=jet(40)
for i=1:size(map, 1)
eval(['rgb', num2str(i), '= map(', num2str(i), ', :)']);
end
Warning: Note that converting your matrix to 40 vectors in this way is probably not the most elegant solution for what you try to obtain. For more information, see Alternatives to the eval Function.

How can I repeat matrix? [duplicate]

This question already has answers here:
how to replicate an array
(4 answers)
Closed 8 years ago.
Could you help me please to repeat matrix. for example if I have matrix(A) and I want to create a big matrix(B) contains three matrices of matrix(A) in the row and two matrices in the column.
The MATLAB function repmat does exactly what you need:
B = repmat(A,3,2);
For more details see the MATLAB documentation
In MatLab, you want to use repmat().
In Python, use the Numpy function, tile(a, (m, n)).
You should check out this post: https://stackoverflow.com/a/1724410/515559

why I cannot get just a number [duplicate]

This question already has answers here:
Convert output from symbolic math (sym) to float
(2 answers)
Closed 8 years ago.
I did following:
clc
clear all
I0=1.2e12;
FWHM=10e-12;
c=FWHM./2.35482;
t=0:1e-12:50e-12;
syms t
int(I0.*exp(-1.*(t-5e-12).^2./(2.*c.^2)),t,0,40e-12)
but it does not give me a simple number (just a number)
The reason why matlab does not automatically give you a number is that precision could be lost.
Suppose you have a symbolic variable with value 1/3. That has infinite accuracy at this point. Yet if you evaluate it, you would lose this precision, so that is why it is not evaluated directly.
If you want to evaluate it, you could do that of course. Try doc double,doc vpa, doc eval or doc subs. I think the first one is what you need.

Matlab how to convert numbers to single precision floating point representation in binary [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Binary representation of a number in Matlab
I am using matlab and would like to convert a number such as 7546.456124865 to single precision.
I've used the single() command, but I would like to get the binary for the single precision floating point. How do I go about doing this?
>> num2hex(single(7546.456124865))
ans =
45ebd3a6