m = magic(4) Dd = diff(diag(m),2) %diagonal Dm = diff(diag(rot90(m)),2) %minor diagonal

http://in.mathworks.com/matlabcentral/answers/16560-second-order-difference

Skip to content
# cloudmicrophysics

# Month: April 2016

# Second Order Difference in MATLAB

# Unwrap the phase

# Importance of trim in string concatenation in Fortran 90

# Fortran Integer to String and vice versa

# Read mixed csv file in MATLAB

# Stream Function and Velocity Potential

Hi I am Manmeet, welcome to my blog, here I share my views and notes on my readings

m = magic(4) Dd = diff(diag(m),2) %diagonal Dm = diff(diag(rot90(m)),2) %minor diagonal

http://in.mathworks.com/matlabcentral/answers/16560-second-order-difference

clear all

clc

r=csvread(‘r.csv’);

phase=csvread(‘phase.csv’);

s = size(phase);

count = s(1);

for i=1:count-1

if(phase(i+1)<phase(i))

phase(i+1:end)=phase(i+1:end) + 6.28;

end

end

It is very important while concatenating strings as not doing it may lead to issues with the size of string array.

Integer I Character* str I = 9999 Write( str, '(i10)' ) I End Here it will be i4 if there are 4 words, or as suitable

Integer I Character* str I = 9999 read( str, '(i10)' ) I End

Source : https://www.solver.io/wp/2012/03/31/fortran-integer-to-string-and-string-to-integer-conversion/

Use this function

```
function lineArray = read_mixed_csv(fileName,delimiter)
fid = fopen(fileName,'r'); %# Open the file
lineArray = cell(100,1); %# Preallocate a cell array (ideally slightly
%# larger than is needed)
lineIndex = 1; %# Index of cell to place the next line in
nextLine = fgetl(fid); %# Read the first line from the file
while ~isequal(nextLine,-1) %# Loop while not at the end of the file
lineArray{lineIndex} = nextLine; %# Add the line to the cell array
lineIndex = lineIndex+1; %# Increment the line index
nextLine = fgetl(fid); %# Read the next line from the file
end
fclose(fid); %# Close the file
lineArray = lineArray(1:lineIndex-1); %# Remove empty cells, if needed
for iLine = 1:lineIndex-1 %# Loop over lines
lineData = textscan(lineArray{iLine},'%s',... %# Read strings
'Delimiter',delimiter);
lineData = lineData{1}; %# Remove cell encapsulation
if strcmp(lineArray{iLine}(end),delimiter) %# Account for when the line
lineData{end+1} = ''; %# ends with a delimiter
end
lineArray(iLine,1:numel(lineData)) = lineData; %# Overwrite line data
end
end
```

And then use it as

```
data = read_mixed_csv('myfile.csv',';')
```

source : http://stackoverflow.com/questions/4747834/import-csv-file-with-mixed-data-types
Then after that we get a cell in data variable, to make a matrix of this cell use
data_m = str2double(data);

courtsey : http://nptel.ac.in/courses/101103004/12