blotch detection
I want to make automatic video inpainting projects with matlab. Firstly i have to detect blotch in video with sift but i don't know what can i do
How to call a function which is in another program MATLAB
I write this in my main program
[code]
[C,rows,cols,entries] = Matrix('C.txt')[/code]
Matrix fuction is in another program Matrix.m and I want to call it.
I get this error :
[code]Undefined function or variable 'Matrix'.
Error in (line 19)
[C,rows,cols,entries] = Matrix'C.txt')[/code]
Can you please tell me how to fix it ?
How can I find each max element of three matrices as new matrix?
Maybe the question is a little bit confused, I'll make an example below.
Let's say I have a 3 matrices a, b, c with same size.
[code]
a = [2, 5; 6, 9];
b = [3, 3; 8, 1];
c = [5, 5; 2, 7];[/code]
How can I get the new matrix max with each max element in all three matrices?
[code]max = [5, 5; 8, 9][/code]
I know I could create logical matrix like a>b and then do the math, calc it out, is there any other more efficient way to do it?
MATLAB App Designer non-Numeric data plotting
UIAxes in Matlab App designer does not support non-numeric data such as a graph plot, is there any alternative to do it inside UI framework?
[img]
https://i.stack.imgur.com/Bgbxb.png[/img]
Reproducible results when creating random matrices across parallel calls in MATLAB
I want to create a number of random matrices, but they are really big to fit in memory, so I'd like to find a way to reproduce them across computers, so that when I need to send them to another machine, I'd just need to send the code. Here is how I want to do it:
[code]num_of_iters = 10;
K = 200;
for iter = 1:num_of_iters
parfor j = 1:K
R = make_random_R(iter,j,.....);
% Do something
end
end[/code]
What I'm worried about is the parfor loop, I need to be able to reproduce the random matrices no matter what the order of indices in the parfor is. So I decided to use a MATLAB stream for this:
Save the global stream
Create a new stream, set the seed and appropriate substream (which depends on iter and j)
Do the math
Put back the global stream
Here is my code (the variables n,p,R_type control how the random matrices are made, but they are not important, and K is the same variable as the one from above, I need it in the line substream_id = (iter - 1) * K + j;) :
[code]function [R] = make_random_R(iter,j,n,K,p,R_type)
% Data as code
% R_type: 'posneg' or 'normdist'
% 1 <= iter <= 100
% 1 <= j <= K
% K: Number of classifiers
% n: Number of observations
assert(strcmp(R_type,'posneg') || strcmp(R_type,'normdist'),'R_type must be posneg or normdist');
assert(iter >= 1,'Error: iter >= 1 not satisfied');
assert((1 <= j) && (j <= K),'Error: 1 <= j <= K not satisfied');
assert(K > 0,'Error: K > 0 not satisfied');
globalStream = RandStream.getGlobalStream;
globalState = globalStream.State;
stream=RandStream('mlfg6331_64','Seed',1);
substream_id = (iter - 1) * K + j;
stream.Substream = substream_id;
RandStream.setGlobalStream(stream);
switch R_type
case 'posneg'
q0=ceil(2*log(n)/0.25^2)+1;
if (q0 < p)
q = q0;
else
q = ceil(p/2);
end
R = randi([0 1],p,q);
R(R == 0) = -1;
case 'normdist'
q = 2*ceil(log2(p));
R = normrnd(0,1,[p,q]);
end
RandStream.setGlobalStream(globalStream);
globalStream.State = globalState;
end[/code]
Tried some code and here it is:
[code]>> iter = 2;
>> j = 3;
>> n=100;
>> K=10;
>> p=6;
>> R_type = 'normdist';
>> for j=1:K
j
make_ran
>> parfor j=1:K
j
make_random_R(iter,j,n,K,p,R_type)
end
Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers.
ans =
7
ans =
-0.3660 0.8816 1.1754 -0.4987 -1.8612 -0.3683
0.9504 -0.3067 -0.5156 -0.2383 -1.1661 0.3622
2.0743 -0.4195 0.5021 0.3954 0.2415 -0.4552
-0.0474 -0.1645 -0.1725 -0.4938 -0.2559 0.2188
1.0735 0.3660 0.1043 0.4403 -0.3166 1.1241
-1.0421 -1.4528 -0.4976 -0.7166 -1.1328 -2.0260
ans =
2
ans =
-1.6629 0.0213 -1.8138 -0.4375 0.3575 -0.0353
0.6653 -1.2662 -0.3977 -0.6540 -1.2131 0.4858
0.3421 1.1266 -0.6066 -1.2095 1.5496 -0.9341
0.2145 0.7192 -2.2087 0.7597 -0.0110 -1.1282
-0.3511 -0.7305 -0.1143 0.0242 0.2431 -0.8612
0.5875 1.2665 -2.1943 -0.4879 0.0120 -1.1539
ans =
1
ans =
-0.5300 2.4077 -0.3478 1.8695 -1.1327 -1.0734
-0.2540 -1.1265 0.3152 0.4265 1.2777 0.0959
0.5005 -0.7557 0.6194 1.5873 0.0961 -1.9216
0.7275 0.5420 -0.6237 -0.2228 0.8915 0.4644
0.8131 -0.1492 0.9232 0.8410 -0.0637 2.1163
-1.1995 0.2338 -1.3726 0.1604 -0.1855 1.3826
ans =
8
ans =
-0.5146 2.2106 2.7200 -1.2136 1.0004 1.3089
0.7225 0.2746 -0.8798 0.2978 -0.8490 1.6744
1.1998 -0.0363 1.9105 -0.7747 -0.8707 -0.6823
0.6801 1.3194 -0.0685 0.5944 1.5078 -1.6821
0.0876 1.2150 -0.0747 0.0324 -1.1552 0.0966
-0.0624 -0.3874 -0.5356 0.6353 1.4090 -1.1014
ans =
6
ans =
0.5866 -1.0222 -0.2168 0.8582 1.4360 0.0699
2.0677 -0.4740 -0.8763 1.7827 0.1930 -1.2167
-0.3941 -0.5441 0.3719 -0.0609 0.7138 -1.0920
0.3622 -0.0459 -0.0221 0.2030 -0.7695 -0.8963
-0.1986 -0.2560 0.6666 0.4831 -1.2028 -0.9423
0.1656 1.2006 -1.1131 0.7704 -0.6906 -1.3143
ans =
5
ans =
-0.5782 -0.3634 1.5381 -1.3173 -0.9493 0.8480
1.5921 -0.4069 0.7795 -0.3390 -0.1071 0.4201
-0.0184 0.2865 -0.1139 -0.1171 0.2288 0.5511
0.1787 0.7583 0.3994 1.0457 0.3291 -0.9150
0.3641 -0.6420 -0.2096 0.7761 0.4022 -0.7478
0.1165 0.7142 0.7029 -1.1195 0.0905 0.6810
ans =
4
ans =
0.1246 -0.3173 0.8068 0.6485 -0.8572 0.2275
0.3674 -0.0507 -0.9196 0.6161 -0.5821 -0.4291
-1.0142 -1.1614 -2.5438 1.5915 2.0356 0.4535
-0.2111 -0.3974 0.0376 0.3825 -1.9702 1.5318
-0.3890 0.9210 -0.0635 0.3248 1.8666 -0.0160
1.3908 -0.7204 -0.6772 -0.0713 0.0569 0.5929
ans =
3
ans =
-0.1602 0.6891 0.4725 0.0277 -2.0510 -2.2440
-0.7497 1.8225 -0.4433 0.4090 0.9021 -1.6683
0.0659 0.3909 0.2043 0.9065 1.4630 0.3091
-0.3886 0.6715 -0.9742 -0.5468 0.2890 0.5625
-0.4558 0.4770 -0.1888 -0.6504 0.3281 1.3767
0.3983 0.5834 0.9360 0.8604 -0.9776 0.6755
ans =
10
ans =
-0.4843 -0.4512 0.7544 0.7585 -0.4417 -0.0208
1.8537 -1.6935 -2.7067 -0.5077 0.9616 -1.7904
-1.6943 -1.0988 0.1208 -0.8100 1.8778 1.1654
1.1759 -0.7087 -1.2673 -0.1381 -0.0710 0.5343
0.2589 -0.5128 -0.3970 0.6737 0.8097 2.7024
-0.8933 0.2810 0.8117 -0.5428 -0.8782 1.1746
ans =
9
ans =
0.0254 -0.7993 1.5164 1.2921 -1.1013 1.8556
-0.6280 0.9374 -0.1962 0.1685 -0.5079 0.4333
-0.3962 -0.9977 0.6971 -1.0310 -1.1997 -2.1391
0.7179 1.0177 -0.8874 -0.6732 0.7295 1.4448
-1.1793 -1.3210 1.5292 0.2280 1.9337 1.0901
-0.0926 0.1798 -1.1740 0.3447 2.4578 0.4170[/code]
I wonder if the code is correct, and does it retain the state of the global stream after the function call? Please help me, thank you very much
How extract (changeable variable) word & number using regular expression matlab
I have more than 10k text files look similar like this, all of them are similar in format but not in size, sometime is bigger or smaller.
[code][{u'language': u'english', u'area': 3825.8953168044045, u'class': u'machine printed', u'utf8_string': u'troia', u'image_id': 428035, u'box': [426.42422762784093, 225.33333055900806, 75.15151515151516, 50.909090909090864], u'legibility': u'legible', u'id': 1056659}, {u'language': u'na', u'area': 24201.285583103767, u'id': 1056660, u'image_id': 428035, u'box': [223.99998520359847, 249.57575480143228, 172.12121212121215, 140.6060606060606], u'legibility': u'illegible', u'class': u'machine printed'}]
[/code]
I want to extract two changeable variable in every text using regular expression.
The output should be like this
[code]box = [223.99998520359847, 249.57575480143228, 172.12121212121215, 140.6060606060606]
box1 = .. sometime there is more than one [/code]
& second output
[code]word = troia
word1 = ... sometime there is more than one word [/code]
My code 1: for the word extraction
[code]fid = fopen('text1.txt','r');
C = textscan(fid, '%s','Delimiter','');
fclose(fid);
C = C{:};
Lia = ~cellfun(@isempty, strfind(C,'utf8_string'));
output = [C{find(Lia)}];
expression = 'u''utf8_string'': u+'
matchStr = regexp(output, expression,'match');[/code]
My code 1 result give me only the
[code]utf8_string[/code]
My code 2: for the box number extraction
[code]s = sprintf('text_.txt');
fid = fopen(s);
tline = fgetl(fid);
C = regexp(tline,'u''box'': +\[([0-9\. ,]+)\]','tokens');
C = cellfun(@(x) x{1},C,'UniformOutput',false)';
M = cell2mat(cellfun(@(x) x', cat(1,C2{:}),'UniformOutput',false));[/code]
This code 2 is running but not with every text something i got this error
[code]Error using cat Dimensions of matrices being concatenated are not consistent[/code]
Retaining color when subsampling a triangulated surface: get indices from reducepatch?
I have a very densely tessellated surface which looks like this: White matter dense
[img]
https://i.stack.imgur.com/gcNFn.png[/img]
This surface is too densely tessellated for me, so I subsample it to get a coarser surface. To do this, I used Matlab's reducepatch function. This works pretty well:
[code]https://i.stack.imgur.com/U6sVm.png[/code]
White matter subsampled
Unfortunately, the coloring is based on a variable called sulcal_depth, which is defined for every vertex of my tessellated surface. So I need to retain sulcal depth information only from the vertices which remain after subsampling. Essentially, I need reducepatch to give me not just the subsampled version of the surface, but also the indices of vertex points that it retained. If I know the preserved indices, I can just index my sulcal_depth variable to get the new depth map.
Currently, I'm doing this as follows (this is also how I colored the subsampled version above):
[code]function indices = compute_reduced_indices(before, after)
%% Function to compute the indices of vertices preserved during an operation of
% reducepatch. This allows you to use reducepatch to subsample a surface and
% re-compute an original signal on the vertices for the new subsampled mesh
indices = zeros(length(after), 1);
for i = 1:length(after)
dotprods = (before * after(i, :)') ./ sqrt(sum(before.^2, 2));
[~, indices(i)] = max(dotprods);
end[/code]
But as you might imagine, this is pretty slow, because of the for loop over vertices. I don't have enough memory to vectorize the loop and compute the full dot product matrix in one go.
Is there a smart way to get reducepatch to give me indices, or an alternative approach (with or without reducepatch) that's faster?
Linprog function in Matlab
I have a system X(k+1) = Ax(k) + Bu(k) and I have a cost function which needs to be minimised. I need to find the optimal u(k) that minimises x(k). How can this be done using 'linprog' function on Matlab? The linear constraints are in terms of u(k) and x(k) but I need to find just the optimal u(k).
I've created MATLAB code here that produces a graph and depending on parameters (some random) converges to a different a
I want to be able to run this 100 times for a certain set of parameter values and take an average of the amount of groups that it produces.
Here is the code I have at the minute. Do I need to create another m file for this or can i do it within the function I've already created?
[code]function [t seqBeliefs] = extendedHK(n, tol, adj)
%extendedHK Summary of function goes here
%Detailed explanation goes here
beliefs = rand(n,1);
seqBeliefs = beliefs; %NxT matrix
converge = 0;
step = 0
t = step
while converge ~= 1
step = step+1;
t = [t step];
A = zeros (n,n);
for i=1:1:n
for j=i:1:n
if abs(beliefs(i) - beliefs(j)) < tol && adj(i,j)==1
A(j,i)=1;
A(i,j)=1;
end
end
end
beliefs = A*beliefs./ sum(A,2);
seqBeliefs = [seqBeliefs beliefs];
if sum(abs(beliefs - seqBeliefs(:,step)))<1e-12
converge = 1;
end
end
plot(t,seqBeliefs)
end
%%in command window type adj=random_graph(n) then call extendedHK function
%%with same n then tol value and 'adj'[/code]