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

DBMS Pl/SQL -- What would be output ... please explain?
CREATE OR REPLACE PROCEDURE sp_validatehostelid ( p_hostelid IN hostel.hostelid%TYPE, p_hostelfee OUT hostel.hostelfee%TYPE ) IS v_count NUMBER; v_hostelfee hostel.hostelfee%TYPE; BEGIN /* Count rows in 'hostel' table for given ID */ SELECT COUNT(*) INTO v_count FROM hostel WHERE hostelid=p_hostelid; /* If there is noting in the table */ IF v_count=0 THEN /* raise exception */ RAISE_APPLICATION_ERROR(-20000,'Invalid Hostel id'); ELSE /* select fee from the 'hostel' table */ SELECT hostelfee INTO v_hostelfee FROM hostel WHERE hostelid=p_hostelid; /* print the fee */ DBMS_OUTPUT.PUT_LINE('Hostel Fee:'||v_hostelfee); END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE

Categories : Oracle

Struct - Explain the output:
No. Output is 2 2 1. The C compiler converts the values to Binary, and stores in the memory. Binary value of 2 : 00000010 Binary value of -6: 11111010 (11111001+1) Binary value of 5 : 00000101 While storing in memory: For 2, 010 will be stored. For -6, 010 will be stored. For 5, 01 will be stored. When you access these variables from your main method, for v.a "010" will be returned, here left most bit is for sign. So v.a is 2. Similarly v.b is 2 and v.c is 1. Hope it helps.

Categories : C

Explain the output of this program?
argc is 5. This program checks each pair of consecutive arguments and counts how many are substrings of each other (either the first is a substring of the second or vice versa): bcd abcd // i = 2 abcd ab // i = 3, good ab abc // i = 4, good In this case, since i=3 and i=4 fit the criteria, k is 7. Breaking down the code, the innermost for loop exits if there is a different character or if one string ends. The line if (!*p || !*q) k += i; increases k only if one of the strings hit the end.

Categories : C

How to Explain this C Union Output
K&R is a great book, but it is old. In C99 You can do this. Using a designated initializer in the same example, the following initializes the second union member age : union { char birthday[9]; int age; float weight; } people = { .age = 14 };

Categories : C

How to explain this output of a C program
+-----------------------+ | F7 <--b=(char *) &a| | FF | | FF | | FF | | | +-----------------------+ printf("%08x",*b); //means : *b asking the value b pointer to (F7) %08x is asking for hex, when printing a char as an integer type it is widened to an int before printing. (FFFFFF7 now)

Categories : C

Explain output of this C program
You're using a variable with an indeterminate value (invoking undefined behaviour) by jumping past the initialization of the variable b. The program can produce any value and it will be correct. The C standard even covers this case (in a non-normative example). ISO/IEC 9899:2011 §6.8.4.2 The switch statement: 7 EXAMPLE In the artificial program fragment switch (expr) { int i = 4; f(i); case 0: i = 17; /* falls through into default code */ default: printf("%d ", i); } the object whose identifier is i exists with automatic storage duration (within the block) but is never initialized, and thus if the controlling expression has a nonzero value, the call to the printf function will access an indeterminate value. Similarly, t

Categories : C

Explain the output of a c program
You are calling a main function from your main function. After you call new main function it will print some string and then again it will call main function. Your i variable will not be incremented at all, because it is not incremented in the first iteration of for loop. After you call main, it will never return to previous main to next iteration of for loop to happen. So the loop will be infinite and i will be equal to 1. Even if you changed the for loop to any other loop, the loop will be still infinite. I'm including your repaired code, just for the fun of it: #include<stdio.h> int main() { static int i=0; if(i>=5) return 0; i++; printf(" Software %i", i); main(); return 0; }

Categories : C

Can somebody please explain me this output of polymorphism?
Class fields don't get inherited. Note that you have the same int data field in both classes A and B. This is called Hiding.

Categories : Java

could you explain the reasons about output when using std::hex and std::wios::hex in C++
std::hex is a manipulator. It sets the stream to output hex when you pass an integer. It is equivalent to calling setf(std::wios::hex, std::wios::basefield); on the stream (assuming wide streams). For example, try the following modification of your code. You should see the same results. wchar_t waTemp2[4] = {0xA0, 0xA1, 0x00A2, 0xA3}; s2.setf(std::wios::hex, std::wios::basefield); for (int i = 0; i < 4; i++) { s2 << (unsigned)waTemp2[i] << " "; } std::wios::hex is a constant number used as a bitmask flag. Do not confuse it with a manipulator which sets the stream. On coliru for example the following prints 8. std::cout << std::wios::hex; It is used as a bitmask to update the format flags on the stream. It will defined something like the following (see the

Categories : C++

Can not explain output of simple string operation in C
This line s = &s[n+1]; is causing your pointer to point off into the middle of nowhere. After that you start reading random garbage from it. Apparently that random garbage includes some % characters.

Categories : C

explain bash variable assignement output
Because echo $test > test2 writes the output to a file named test2. this set of commands is does what you would expect: test="zut"; echo $test; test2=$test; echo "echo test " $test2

Categories : Bash

Can anyone explain why statements after a cout would change the output?
I didn't reproduce your problem, but according to the MSDN page for GetGUIThreadInfo Note that you must set the cbSize member to sizeof(GUITHREADINFO) before calling this function. Those extra 7 HWND affected your stack frame, causing cbSize to be filled with different values

Categories : Windows

how to code for checkbox to get pattern output explain below
I suppose you did your checkbox with array (new...) if not do it maunally... int min=13; int max=0; string s = ""; for (int i = 0; i<12; i++) { if (cb[i].checked && i<min) min = i; else if (cb[i].checked == false) if (min != 13) { max = i-1; s = s + min.ToString() + "-" + max.ToString() + " "; min = 13; } } if (cb[11].checked) s = s + min.ToString() + "-12"; // for case the last one is checked // s contains your data (I didn't check it but I think it need to be something like this.)

Categories : C#

How do you explain the output from this function-like macro `slice` in C?
slice(bare_string,start_index) #bare_string+start_index you are passing a string and bare_string stores the starting address of string which you have passed and then you returning changed pointer location which is bare_string+start_index char str[6]="Hello"; char *ptr =str; printf("%s ",str);//prints hello printf("%s ",str+1);//prints ello printf("%s ",str+2);//prints llo printf("%s ",str+3);//prints lo printf("%s ",str+4);//prints o printf("%s %c=%d ",str+5,*(str+5),*(str+5));//prints Null printf("%s %c=%d ",str+6,*(str+6),*(str+6));//prints Null or may be Undefined behavior printf("%s %c=%d ",str+7,*(str+7),*(str+7));//prints Null or may be Undefined behaviour the same scenario is happing in your case. Test Code: #include<stdio.h> main() { char str[6]="H

Categories : C

please explain this javascript debugger output regarding Date constructor
The Invalid Date is normal. That is just what the debugger prints for the proto object of a Date. I believe this is because the debugger calls the toString method on the proto object without supplying the actual Date instance, and so the toString method returns "Invalid Date". I suggest you read the MDN documentation on Date. You can just use new Date(caldate) to create a Date from your string.

Categories : Javascript

Please explain the nested switch-case statements in the following C program and the corresponding output
The switch statement is just a jump into the middle of a for loop (at case label 2). Then the code executes the for loop. Pretty much equivalent to: #include <stdio.h> int main() { int i=5; goto label_2; for ( i=0; i<10; i++ ) { printf("A i=%d ",i); label_2: printf("B i*i=%d ",i*i); }; label_3: printf("done"); return 0; } That's all there is to it.

Categories : C

Explain 2D array iteration with 1 loop
You are not using it as a 1D array. You are still indexing it as a 2D array. However, you're using maths (modulo and integer division) to recover the 2D indices from a 1D index based on the array's dimensions. This is pretty normal, but it's unusual to do this in a loop the way you've done so, as it could be computationally expensive.

Categories : C++

Why was the explain query output giving me BasicCursor eventhough the collection had indexes on it?
I'm pretty sure that the issue here is your use of the find() function. You are specifying a query parameter and inside it, placing your search criteria. I don't think that you need to actually put query in there. Simply insert your search criteria. Something like this: db.stocks.find({ symbol: "AAPLE", date: "2014-01-18", type: "O", isValid: true }).sort( { "price": 1} ).explain(); Note also my changes to the sorting. You can read more about sorting a cursor here.

Categories : Mongodb

Explain the speed difference between numpy's vectorized function application VS python's for loop
numpy is written in C. The difference you're seeing isn't due to anything fancy like SSE vectorization; it's just that the C implementation doesn't have to go through the tons of runtime method dispatch and exception checking and so on that a Python implementation goes through.

Categories : Python

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

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

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

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

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

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

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

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

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

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++

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

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 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

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

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

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

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

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

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

Capture real-time command window output in Matlab
You can't do that with MATLAB's dos (or the related system and unix), because they (as you have already noted) are synchronous and only return once the application has finished. What you need is to run the external program and your waitbar code asynchronously. This cannot be done in pure MATLAB code, but it's possible to do using Java (which can be used directly from MATLAB): Write a class in Java that runs your program and collects the output asynchronously. See this answer on SO for details. Have your Java class call a MATLAB callback when new output data is read. The MATLAB callback can then update the waitbar. See this post on undocumentedmatlab.com for more information.

Categories : Matlab



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