How to convert E numbers in MatLab [duplicate] - matlab

This question already has answers here:
Avoiding scientific notation with Matlab
(2 answers)
Closed 6 years ago.
I created a loop using tic toc in MatLab with the below code
tic
for i = val52
val50(i)=i;
end
toc
i then divide the result by 128 (samply frequency) however i get a number which says 2.0516e-05how can I convert this number into a normal number?

If you do not want the e symbol then you can use fprintf instead of disp:
a= 1/12345678;
formatSpec = 'a is %8.13f \n';
fprintf(formatSpec,a)
>> a is 0.0000000810000

Related

# in Function definition in Matlab [duplicate]

This question already has answers here:
What is the # operator (at sign) in MATLAB?
(3 answers)
#(t) mean in Matlab? [duplicate]
(2 answers)
Closed 4 years ago.
I was just browsing through a code and I found the following line :
other_function(#(t)(xx(t,g)))
where other_function,xx are already defined functions and g is already defined.
Here is the code for xx
function [val]=xx(x,y)
val=x+y;
end;
SO now I am unable to understand the meaning of #(t)(xx(t,g))
It is a function handle. It is useful to pass functions as parameters. You can find more in the MATLAB documentation
Just an example: suppose you have a simple function
function y = computeSquare(x)
y = x.^2;
end
than you can compute an integral in this way:
q = integral(#computeSquare,0,1);
In your example: other_function declares as an input parameter a function t and another parameter called g.

MATLAB find the point of a value obtained using min [duplicate]

This question already has answers here:
How do I get the index of the smallest element in an array in matlab?
(2 answers)
Closed 8 years ago.
I want to match a time to the minimum value of TEMP found in an array that I'm reading into a struct from a netcdf file in a loop (that's doing a lot more stuff - no I don't want to get rid of the loop). I have the snctools so that's what I'm using for netcdfs.
Here's my current relevant lines of code:
%Get the netcdf file with file_string loading into MATLAB
nc=netcdf(file_string);
%Work out the number of files I need to loop through
[files]=dir('*.nc');
max1=length(files);
for d1=1:max1
%extract the TEMP 1-D array
B1=nc{'TEMP'}(:)
%assign to value
dat.TEMP_min(d1)= min(B1);
end
Now there is another variable of the same length called 'TIMES'. If min(B1)=10.5 and is the nth element of B1 then I want to locate the nth element of TIMES and save it as dat.TEMP_min_TIME. How would I go about this?
Please provide enough notes on any code so that a novice can understand it.
You can just use inside your loop (sorry for pseudocode, not sure about your definitions of n and TIMES)
[M,I] = min(B1);
dat.TEMP_min(d1)= M;
if (I == n)
dat.TEMP_min_TIME = nc1{'TIMES'}(I); %
end

Quicker way to access a particular column of a function result in matlab [duplicate]

This question already has answers here:
How can I index a MATLAB array returned by a function without first assigning it to a local variable?
(9 answers)
Closed 9 years ago.
I was asking myself if there was a quicker way to do this in matlab :
Imagine we have a 10x2 vector V and we want to use the x dimension (number of lines, here 10) in a function or do whatever we want with it. The way I usually do it is this :
[x y]=size(V);
function(x)
But would it be possible to make it differently? Soemething like
function(size(V)(1))
Thanks for your help !
MATLAB's size can take a second input argument, indicating the dimension of which you would like to know the size. The output is scalar in that case:
x = size(V,1);
y = size(V,2);
See help size for more details.

How to vectorize a loop in matlab [duplicate]

This question already has answers here:
Structure initialization with repmat
(2 answers)
Closed 9 years ago.
I want to use a function repmat to write this code:
for j=1:30
for i=1:10
myObject{i,j}.s = zeros(6,1);
end
end
I cannot understand how to do that for cells. Can anyone help me please?
You can use deal:
[myObject{1:10,1:30}] = deal( struct('s',zeros(6,1) );
PS: It is best not to use i and j as variables in Matlab.

MATLAB question: quote value of variables in the tile of a plot [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
matlab - variable in plot title
I would like to quote the value of variables defined in the m-file in the plot such as
let us say I define
d = 1;
in the MATLAB code. I want to plot with the title such as
title('The Distribution of Some Variable when the Parameter is %d')
Please advise.
title(sprintf('The Distribution of Some Variable when the Parameter is %d', d));
title(['The Distribution of Some Variable when the Parameter is ' num2str(d)])
Brackets ['concatenate ' 'strings'] and num2str() converts a number (integer or decimal) to a string.