w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
output iteration results from a loop in Matlab
You are making a mess with the indexes… It is a bit hard to understand what you did on your code, but it may be something like this (pseudocode since the code you gave does not have the result declared): slope=zeros(1,max(L)); % Pre allocate zeros, one index for each interation time=zeros(1,max(L)); position=zeros(1,max(L)); a=zeros(1,max(L)); b=zeros(1,max(L)); for p=1:max(L) % max L gives the number of result{n}. so if max(L)=6 we have from result{1} to result{6} and therefore 6 final values that i want to get% a(p)=result{p}(:,1); b(p)=result{p}(:,2); B = [ones(length(a( p ),1) a( p )] b( p) % this is to obtain the slope and intercept of a lin. regresion slope( p) = B(2) time( p) = result{p}(end,1)-result{p}(1:1) position( p) = (slope( p ).*result{p}(end,1)+inte

Categories : Matlab

Convert the output of a function into a structure in matlab
It is possible, but not in a one-liner that you are looking for. Say you have N outputs then you can use c = cells(N,1); [c{:}] = function(arg1,arg2,...); structure = cell2struct(c, {'output1' 'output2' ...}, 1);

Categories : Matlab

When using a multiple-output matlab function, do i need to callback all variables?
When calling (almost) any function in matlab you can request fewer outputs than it specifies. So, yes the example you give should work perfectly fine. There are some clever things you can do with this, such as using nargout within a function to see how many output arguments have been requested and only calculating the values that have been requested as an optimisation trick.

Categories : Matlab

How do I pass a struct field as a function output in MATLAB?
What you can do is ignore the struct in the function and only use it when the function is called. For example: function output = my_function(input) % manipulate... output = 3*input; When you call the function, you use the struct: myStruct.myField = my_function(input)

Categories : Matlab

Matlab: Return input value with the highest output from a custom function
What you described is a good way to do it. outcomeVec = myfunc(myVec); [~,ndx] = max(outcomeVec); myVec(ndx) % input that produces max output Another option is to do it with a loop. This saves a little memory, but may be slower. maxOutputValue = -Inf; maxOutputNdx = NaN; for ndx = 1:length(myVec) output = myfunc(myVec(ndx)); if output > maxOutputValue maxOutputValue = output; maxOutputNdx = ndx; end end myVec(maxOutputNdx) % input that produces max output Those are pretty much your only options. You could make it fancy by writing a general purpose function that takes in a function handle and an input array. That method would implement one of the techniques above and return the input value that produces the largest output.

Categories : Arrays

Transformation 2 input 2 output transfer function into state space model using MATLAB
Converting to a SS model is always an ugly process, and depending on the method you can get different representation. So don't obsess over getting equal values of A B C and D. Also, the states of SS that have been converted from TF often have no meaning other the storing information of the previous state. To verify whether you have similar SS system, throw in an impulse response: impulse (sys, sysSimulink) From the documentation: Recommended Working Representation You can represent numeric system components using any model type. However, Numeric LTI model types are not equally well-suited for numerical computations. In general, it is recommended that you work with state-space (ss) or frequency response data (frd) models, for the following reasons: The accuracy of

Categories : Matlab

Loop does not print function output
If you just want to see the output, wrap your function in a print command. for (i in 2:inputnumberobjects) { cat(paste("BOOT CONFIDENCE INTERVALS FOR COEFFICIENT ", inputnamesobjects[i], ": ", sep="")) print(boot.ci(bootResults, type = "bca", index=i)) ### Result for Coefficients }

Categories : R

Matlab function with vector output return whole vector
If the function is your own or you can modify it you could do something like this using varargout and nargout: function varargout=quat2angle(a) % Create example output for demo c1 = a; c2 = 2*a.^2; c3 = 3*a; % Switch output format based on how many output arguments user specified if nargout <= 1 varargout{1} = [c1;c2;c3]; else varargout{1} = c1; varargout{2} = c2; if nargout > 2 varargout{3} = c3; end end The use of varargout isn't entirely necessary as you could simply choose to return c1 = [c1;c2;c3]; if nargout <= 1. But for more complex situations this is the sort of thing you'd do. If the function can't be modified then you no other choice than [c1,c2,c3] = quat2angle(a); [1 2 3]' - [c1;c2;c3]

Categories : Matlab

LINES(M) unique colors Matlab
The lines color map has only 7 unique colors (as you have already spotted). If you need more than 7 unique colors, you'll have to create a map by yourself. One option is using rand: >> rCmap = rand( n, 3 ); % create a random map with n colors - usually unique.

Categories : Matlab

Can you obtain an unique identifier for a MATLAB object?
You can use the UserData field, which is present in every graphical object, to store a unique identity generated by you. If working with a user-defined class, you can add a similar field in your class. The identities can be kept unique by using a global counter to assign each new identity.

Categories : Matlab

find out unrepetitive, unique data pair in matlab
try this: unique(data,'rows') C = unique(A,'rows') treats each row of A as a single entity and returns the unique rows of A. The rows of the matrix C are in sorted order. The 'rows' option does not support cell arrays.

Categories : Matlab

octave/matlab - convert string into matrix of unique words
On matlab: string = 'one two three one one four five two three five four' % Convert it to a cell string: cell_string = strread(string,'%s'); % Now get the unique values: unique_strings=unique(cell_string,'stable') If you want char array with the unique values separated with spaces, add the following lines: unique_strings_with_spaces=cellfun(@(input) [input ' '],unique_strings,'UniformOutput',false) % Add a space to each cell final_unique_string = cell2mat(unique_strings_with_spaces') % Concatenate cells final_unique_string = final_unique_string(1:end-1) % Remove white space Output: 'one two three four five'

Categories : Matlab

SQL output unique visitors for each hour
It gets complicated with CASE statements, but here you are. I felt like a challenge before going to bed table stats(id,unique_visitors,time_period) select DATE_FORMAT(time_period ,'%Y-%m-%d') as date, sum(CASE WHEN EXTRACT(hour from time_period) = 00 THEN unique_visitors ELSE 0 END) as '00', sum(CASE WHEN EXTRACT(hour from time_period) = 01 THEN unique_visitors ELSE 0 END) as '01', sum(CASE WHEN EXTRACT(hour from time_period) = 02 THEN unique_visitors ELSE 0 END) as '02', sum(CASE WHEN EXTRACT(hour from time_period) = 03 THEN unique_visitors ELSE 0 END) as '03', sum(CASE WHEN EXTRACT(hour from time_period) = 04 THEN unique_visitors ELSE 0 END) as '04', sum(CASE WHEN EXTRACT(hour from time_period) = 05 THEN unique_visitors ELSE 0 END) as '05', sum(CASE WHEN EX

Categories : Mysql

While loop inside for loop in Matlab
With the example you showed, you have to initialize b or the while-statement cannot be evaluated when it is first called. Do it inside the for-loop to avoid false positives after the first for-iteration: n=100; for ii=1:n b = 0; while b<0.5 x(ii)=rand; b=x(ii); end end Or, without b: n=100; x = zeros(1,100); for ii=1:n while x(ii)<0.5 x(ii)=rand; end end

Categories : Matlab

Get Unique values during Loop
var merhcData = {}; var amName = {}; // and so on for (var i = 0; i < finalArray.length; i++) { merchData[finalArray[i].merchName] = finalArray[i].merchName; amName[finalArray[i].amName] = finalArray[i].amName; // and so on } If you are sure, that data in merchName will never be equal amName or other field - you can use one data object instead of several (merchData, amName...)

Categories : Javascript

Unique radio name in php while loop
you can set a variable counter: $counter = 1; while($res2 = mysql_fetch_array($sql2)){ echo '<input type="radio" name="ch'.$counter++.'[]" value="'.$counter++.'">'; }

Categories : PHP

need to use forEach loop twice with unique id
You can give that tr a className of child instead of id of child. Then you can use a javaScript function that does document.getElementsByClassName('child') and use for loop to style these elements as hidden. <!DOCTYPE html> <html> <head> <script> function load() { var elements = document.getElementsByClassName('child'); for(var i=0; i<elements.length; i++){ elements[i].style.display='none'; } } </script> </head> <body onload="load()"> <table> <tr>Trs wont appear below</tr> <tr class="child"><td>Child1</td></tr> <tr class="child"><td>Child2</td></tr> <tr class="child"><td>Child3</td></tr> <tr class="child"><td>Child4</td></

Categories : Java

generate unique ID for on foreach loop?
first: remove this or put it outside of the foreach loop : $count = 0; second: don't use only number for id and use it with a character or word like this : id = "element'.$count.'" Third : what is $i ? if it's useless remove it! Forth change ++count to ++$count CODE : <?php $i = 0; $count = 0; foreach ( $payment as $payment_id => $items ) { foreach ( $items as $item ) { $i++; // Echo, need to show unique ID in both $count, it must be the same echo '<p><strong><a href="#">Link</a></strong> <br/><a href="#" class="show_info" id="info_'.$count.'">Show Details</a> <div id="payment_info_'.$count.'" style="display:none;">'; ++$count;

Categories : PHP

php output txt files with record limits plus grouped by unique county names
You need a counter, and then be able to reset it (upon resetting it, you save the file). Example (untested, example only): <?php $rowCounter = 0; $fileCounter = 1; $startID = md5(microtime(1)); $fp = fopen("{$startID}.txt", "w"); while ($row = mysql_fetch_array($result)) { $rowCounter++; fwrite($fp, $row['county_txt']." "); if($rowCounter == 2500) { fclose($fp); if($startID) { rename("{$startID}.txt", "Red-#{$fileCounter}-".date("Ymd")."-{$rowCounter}.txt"); $startID = md5(microtime(1)); } $fp = fopen("{$startID}.txt", "w"); $rowCounter = 0; $fileCounter++; } } // Save last file fclose($fp); rename("{$startID}.txt", "Red-#{$fileCounter}-".date("Ymd")."-{$rowCounter}.txt"); ?> On that note, don't use mysql_* functions. Instead, use mys

Categories : PHP

Matlab - Check if function handle is a particular function or function type
How about using func2str? If this is an inbuilt function, it should just return a string containing the function name; if it is an anonymous function it should return the anonymous function (including @). h1 = @(x) x.^2; h2 = @mean; str1 = func2str(h1); %str1 = "@(x) x.^2" str2 = func2str(h2); %str2 = "mean" You can also use isequal to compare two function handles (ETA: this will not work to compare two anonymous functions unless one was created as a copy of the other): isequal(h1,@mean); % returns 0 isequal(h2,@mean); % returns 1

Categories : Matlab

How to create unique ID and name created in a loop within Razor
Not sure how you are thinking about binding this back to your model, but here is are couple ways you can do it: 1. @{ int i = 0; } @foreach (var food in shoppingList.Foods) { @Html.DropDownList("food-" + i.ToString() , new SelectList(Model.Foods,"FoodID","Name",@food.FoodID)) i++ } 2. @{ int i = 0; } @foreach (var food in shoppingList.Foods) { @Html.DropDownListFor(m => food , new SelectList(Model.Foods,"FoodID","Name",@food.FoodID), new { @id = "food-" + i.ToString() }) i++ }

Categories : C#

Wordpress Loop - Only Unique Values for Meta_Key
while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; $colors[] = get('color'); // Creates an array of all colors endwhile; $colors = array_unique($colors); // Removes duplicates; foreach($colors as $color){ echo $color; }

Categories : PHP

Bash: how to redirect continuous output to text file but make lines unique?
Change this tcpdump -lvi any "udp port 53" 2>/dev/null|grep -E 'A?'|awk '{print $(NF-1)}' To: tcpdump -lvi any "udp port 53" 2>/dev/null|grep -E 'A?'|awk '{a[$(NF-1)]++}END{for(i in a)print i}'

Categories : Bash

Use textscan in Matlab to output data
Try this: FID = fopen('datafile.dat'); data = textscan(FID,'%f %f %f %f', 'headerLines', 6); fclose(FID); data will be a 1x4 cell array. Each cell will contain a 3x1 array of double values, which are the values in each column of your data. You can access the 2nd and 4th columns of your data by executing data{2} and data{4}. With your original code, the main issue is that the data file has 6 header lines but you've specified that there are only 4. Additionally, though, you'll run into problems with the specification of the number of times to match the formatSpec. Take for instance the following code data = textscan(FID,'%f',4); which specifies that you will attempt to match a floating-point value 4 times. Keep in mind that after matching 4 values, textscan will stop. So for th

Categories : Matlab

Save matlab output in textfile
You can do this with fprintf in a for loop: x=[0 1 2 3]; y=[4 5 6 7]; file = 'test.txt'; fh = fopen(file, 'wb'); if( length(x) ~= length(y) ) error('x and y must have the same length'); end for k = 1:length(x) fprintf(fh, '%f %f ', x(k), y(k)); end fclose(fh); I assumed that you want to save floating point numbers. To save integer numbers use %d instead of %f.

Categories : Matlab

Matlab output - Space padding?
You can use string formatting to allocate specific number of characters per displayed number. For example fprintf('% 5d ', 12) prints 12 in 5 characters, padding the un-used 3 leading characters with spaces.

Categories : Matlab

Output positions of Matlab figures
Try displaying your images with 'InitialMagnification' set to 'fit': >> figure(1); imshow( A, 'InitialMagnification', 'fit' ); If this does not work, you might try set 'Position' of figure after showing the image. Alternatively, you might want to consider using imagesc with axis image to display the images.

Categories : Matlab

Matlab QR householder factorization incorrect output
It looks like you're not reducing the size of the blocks on each iteration. Everything seems to be a function of the same m and n (which you didn't define in your code). See the line on the Wikipedia page where they define A′ and use it to build Q2 (just the lower two thirds). Below is some code of mine adapted to perform QR-decomposition of 3-by-3 matrices that might help. Note particularly that the second block only works on A(:,2) and q(2:3,:): function [q,r]=qr3(A) u = A(:,1); u(1) = u(1)-(1-2*(u(1)<0))*norm(u); % Flip < to > to match sign convention of qr u = u/norm(u); u(~isfinite(u)) = sqrt(3)/3; q = -2*(u*u'); q([1 5 9]) = q([1 5 9])+1; u = q(2:3,:)*A(:,2); u(1) = u(1)-(1-2*(u(1)<0))*norm(u); % Flip < to > to match sign convention of qr u = u/norm(u); u(~

Categories : Matlab

Save matlab output to text file
You can save the variable(s) containing your cross-validation results using save and load them later using load. For example, assuming you have the results in the variable called accuracies: save('cross-validation-results.txt',accuracies); and later load('cross-validation-results.txt'); to reobtain the variable accuracies. To implement this in your code, save the tuning parameters and the associated accuracy into arrays and then save said arrays.

Categories : Matlab

Sobel filter output from opencv and Matlab different
This code gives me the same result as MATLAB code: int main(int argc, char* argv[]) { namedWindow("result"); Mat img=imread("D:\ImagesForTest\1.tiff",0); img.convertTo(img,CV_32FC1,1.0/255.0); Mat h,v,g; cv::Sobel(img,h,-1,1,0,3,1.0/8.0); cv::Sobel(img,v,-1,0,1,3,1.0/8.0); cv::magnitude(h,v,g); // Check extremums double m,M; cv::minMaxLoc(g,&m,&M); cout << m << ":" << M << endl; cv::minMaxLoc(h,&m,&M); cout << m << ":" << M << endl; cv::minMaxLoc(v,&m,&M); cout << m << ":" << M << endl; imshow("result",g); cv::waitKey(0); } OpenCV never scales convolution result, so, be careful.

Categories : C++

How to obtain larger output window in MATLAB?
Mathworks has provided some function for doing this: http://www.mathworks.co.uk/support/solutions/en/data/1-3MY8PN/index.html?solution=1-3MY8PN You can resize the window to make it the size of the screen (though the window will not be "maximized"), without having to download extra files: http://www.mathworks.co.uk/support/solutions/en/data/1-4TEZ9X/index.html?product=SL&solution=1-4TEZ9X There are lots of matlab examples online, so searching is highly recommended.

Categories : Matlab

How to display our output meseeges into specified uipanel in Matlab GUI?
There are many ways to do this, but it is hard to guess the most appropriate way without some information on what you already tried. I would suggest the following options: If your uipanel is not high and is used much like statusbar in gui applications then you better add a static text component to it and update its text through its handle. While static test can also display multiline text it will not display scrollbars. If you want to display something like a message log window with several lines visible and scroll bars, I'd suggest to add a listbox instead. However, it will be a little tricky if you want to show only limited number of most resent messages.

Categories : Matlab

How do you format complex numbers for text output in matlab
I don't know if there is an easy way, but you can write your own format function (the hard way): function mainFunction() st = sprintfe('%d is imaginary, but %d is real!',1+3i,5); disp(st); st = sprintfe('%f + %f = %f',i,3,3+i); disp(st); end function stOut = sprintfe(st,varargin) %Converts complex numbers. for i=1:numel(varargin) places = strfind(st,'%'); currentVar = varargin{i}; if isnumeric(currentVar) && abs(imag(currentVar))> eps index = places(i); formatSpecifier = st(index:index+1); varargin{i} = fc(currentVar,formatSpecifier); st(index+1) = 's'; end end stOut = sprintf(st,varargin{:}); end function st = fc(x,formatSpecifier) st = sprintf([formatSpecifier '+

Categories : Matlab

why doesn't reshape() in MATLAB give me the same output as matrix() in R?
In MATLAB matrices are stored column-wise. What your reshape does is take a row vector of 1:6, and start filling out a new 3-by-2 matrix column-wise: 1 4 2 5 3 6 The apostrophe after the reshape transposes this to produce: 1 2 3 4 5 6 To obtain what you actually want, create a 2-by-3 matrix using reshape first, then transpose it. reshape(1:6, 2, 3)'

Categories : R

Save exact image output from imagesc in matlab
To save the figure as a file (don't matter how it was created), one should do: saveas(figureHandle,'filename','format') where figureHandle could be the gcf handle, which means: get current figure. As pointed in the discussion, if someone doesn't want the ticks to be shown, the person can add: set(gca,'XTick',[]) set(gca,'YTick',[]) where gca is the handle to the current axis, just as gcf. If you have more than one axis, don't forget to "handle the handles". They are returned to you when you create them, i.e.: hFig = figure(pairValuedProperties); % Create and get the figure handle hAxes1 = suplot(2,1,1,pairValuedProperties); % Create and get the upper axes handle hAxes2 = suplot(2,1,2,pairValuedProperties); % Create and get the bottom axes handle where the pair value are the figur

Categories : Matlab

Increase Hex2dec or dec2hex output range in Matlab
You need to use uint64 to store that value: A='123123123123123A'; B=bitshift(uint64(hex2dec(A(1:end-8))),32)+uint64(hex2dec(A(end-7:end))) which returns B = 1310867527582290490

Categories : Matlab

Adding space between cells in Matlab imagesc output
You can add spaces between patches of color using another function than imagesc. Here, scatter provides a straightforward solution when used with option 'filled' and marker 'square'. Note that you need to transform your 2-D matrix into a vector, but you don't have to scale your data: scatter takes the min and max values from your data and assign them to the min and max colors of the colormap. The code % 2-D in 1-D: Z = diag(1:10); %example of 2-D matrix to be plotted C = reshape(Z,1,[]); %1-D transform for vector color % input definition sz_matrix = 10; X = repmat( (1:sz_matrix), 1, sz_matrix); Y = kron(1:sz_matrix,ones(1,sz_matrix)); S = 1000; % size of marker (handle spaces between patches) %C = (X.^2 + Y.^2); % second color scheme %plot figure('Color'

Categories : Matlab

Multiple Text Files to a Single Output (Matlab)
You could do this outside of MATLAB: click here if you're on OSX/Linux click here if you're on Windows If you really want to stick to MATLAB, A = []; for ii = 1:length(files) % load new contents newA = load(files(ii).name, '-ascii'); % concatenate horizontally A = [A newA]; %#ok end % save final output save('outputFile.txt', 'A')

Categories : Matlab

Converting MATLAB 'imagesc' function to work with R's 'imagesc' from R's 'matlab' library
As I read the question and the linked material and some other material found with Google, you want the combined capacities of the image and axis functions in R. Some of the other material said that imagesc really only relabels the axis annotation. (And it has some additional color scaling capacity that you don't seem to be requesting.) Reading images in from files may take some extra packages. There is a grImport package with useful capabilities for pdf. There are also packages that specialize in particular formats, eg. tiff or rtiff. If you have a modes sized matrix to plot, you should offer dput(mat). In the absence of an example and specific directions can offer this adaptation of an example in the middle of the Examples section of ?image. > image(t(volcano)[ncol(volcano):1,]) #

Categories : R

Rasterized PDF output after manually setting 'FaceVertexCData' of a patch in MATLAB
I have solved the problem. For posterity: The workaround for this is to not specify RGB colors directly, but define them in a color map, which is then indexed. The following code will solve the problem: clear all; close all; % Make the bar plot h = bar([1 2 3 ; 3 2 1 ; 3 4 4]); ch = get(h,'children'); % Define the colors in a color map cMap = [1 0 0 ; 0 1 0; 0 0 1]; colormap(cMap); % Now set the FaceVertexCData by indexing into the colormap set(ch{1},'CDataMapping', 'direct', 'FaceVertexCData',[1 2 3]'); set(ch{2},'CDataMapping', 'direct', 'FaceVertexCData',[1 2 3]'); set(ch{3},'CDataMapping', 'direct', 'FaceVertexCData',[1 2 3]'); % Save out, this will produce vectorized PDF saveas(gcf, 'barplot_savefig_FaceVertexCData.pdf', 'pdf'); savefig('barplot_saveas_FaceVertexCData.pdf', 'p

Categories : Matlab



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.