w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Get colormap value matlab
Step 1: You can convert the RGB to grayscale or just choose a single color channel. Step 2: Use imagesc to plot that matrix. Step 3: Use colormap to adjust the colorscale to be from -90 to 90.

Categories : Image

MATLAB: generating a colormap given three colors
I would use linspace: cmap=[linspace(oldRed,newRed,steps)' ... linspace(oldGreen,newGreen,steps)' ... linspace(oldBlue,newBlue,steps)']; And then for do the same for your next step, and concatenate them: cmap_full = [cmap;cmap2];

Categories : Matlab

matlab bar colormap returns the same color for all bars
See Coloring 2-D Bars According to Height in the MATLAB documentation. Only the first colour of the colormap is used to colour the faces, you need a bit of hack (as per code on that doc page) to do what you want.

Categories : Matlab

Matlab, values over specific y-range
I think you're looking for something like this: T = rand(100,1); %Your temperature variable c = (T > 0.2) & (T < 0.8); %Your threshholds, in your case switch the 0.2 for 550 and the 0.8 for 600 sum(diff([0; c]) == 1) What's happening here is this: c = (T > 0.2) & (T < 0.8) creates a mask where points that are between your threshholds are 1 and points that are outside are 0. Now diff finds the difference between each adjacent point so for example diff([1 0 0 1 1 1 0]) will return -1 0 1 0 0 -1 but we only want to count each time our c vector goes from 0 to 1 (or we could count it going from 1 to 0, so long as we don't count both) hence the == 1. Finally we don't want to miss a gorup of ones starting at the beginning hence we add a 0 to the beginning. EDIT:

Categories : Matlab

how to save values to .dat file in specific format using matlab
First you have to convert the data to hex: myHexData = dec2hex(myDecimalData) Then you can save it, as explained here and mentioned in the comments by Deve: how-to-save-values-to-text-file-in-specific-format-using-matlab

Categories : Matlab

Recursive solutions inside Iterative solutions
This got to work as long as you don't exhaust the shell's stack space by entering thousands and thousands of invalid inputs. Since it works, it is viable. However, I find it harder to grasp than a while-loop, and prefer the latter; but that might be a matter of taste. Certainly there are applications for recursion inside an iteration, but not like here, where the iteration never continues after return from recursion. Refrain from recursion. ;-)

Categories : Bash

Combine 2 solutions and share modules between solutions
Say your file is in solution 1. Open Solution 2, rt-click the project you want to add to and select 'Add', 'Existing Item'. Browse to the file, then on the 'Add' button, extend the drop-down and click 'Add as link'

Categories : Vb.Net

Are my solutions to printing an error due to file size and storing values right?
Part 1 Function should take void arguments - this means none. You want an or. Error if width OR height are too big. Minor style note, you should be using the #defines here and they should be all uppercase. void check_file_size(void) { if (width > MAX_WIDTH || height > MAX_HEIGHT) { perror("Error: File size too big. "); } } Part 2 You can loop through an array here like you are, but it's actually much nicer to cheat. A C array of arrays or a straight array is the same thing with slightly different syntactic sugar. Read the whole file into an array, see Reading the whole text file into a char array in C for implementation hints. Cast the buffer into the final structure that you want. // Make struct rgb match your data, details not supplied i

Categories : C

Fixing values/numbers to 2decimal places
Use the in built function number_format like so: number_format($number, 2); If you don't want to add thousand seperators, you can simply skip it: number_format($number, 2, '.', ''); // ^ No thousand seperator

Categories : PHP

MATLAB: Matrix containing values of another matrix at specific indices
You can't do it for randomly generated matrices, because you have to ensure that matrix A has lines and columns as required from the values of x and y. In this case, you can write: for i=1:length(x(:)) B(i)=A(x(i),y(i)); end B=reshape(B,size(x));

Categories : Matlab

Matlab reading hex values from text file with non hex values interspersed?
This solution reads 1 million 2-character lines in less than a second on my laptop: fid = fopen('test.txt'); A = textscan(fid,'%2c','CommentStyle','XX'); fclose(fid); A = hex2dec(A{:}); Note the 'CommentStyle' option that skips those lines that start with XX.

Categories : Matlab

Select specific columns with average of specific row values using joins in CodeIgniter
You need GROUP BY $this->db->select('table1.id, table1.name, table1.email, AVG(table2.rating)'); $this->db->from('table1'); $this->db->join('table2', 'table1.id = table2.review_id', 'inner'); $this->db->where(array('table1.status' => 1, 'table1.b_id' => $bid)); $this->db->group_by(array('table1.id','table1.name', 'table1.email')); $query = $this->db->get(); return $query; UPDATE To get correct average when rating = 0 you can use the fact that AVG() doesn't take into account NULLs. Therefore you can use IFNULL() or CASE in your select part $this->db->select('table1.id, table1.name, table1.email, AVG(NULLIF(table2.rating, 0))'); A base sql query should look like SELECT t1.id, t1.name, t1.email, AVG(NULLIF(t2.rating, 0)) rating FROM tab

Categories : Mysql

Converting 3D Image Into Colormap
Imagine your 2D/3D image as a square/cube of color. What you want to do (if I understand correctly), is color each point in myData depending on where it falls into that square/cube. However, that's not how 'CData' works in Matlab. It maps colours based on indexed location, not the actual values in the matrix. Therefore if your data is M-by-N, your colormap is M-by-N - e.g. regardless of the actual values of the data, myData(1,1) is coloured according to myColormap(1,1). In the case of the M-by-N-by-3 array, these are still just indexed locations, but the three values in each case define the colour in RGB. It is possible to do what you want, you just have to tell Matlab directly what color in that 512 x 512 x 351 cube you want to apply to each point. Presuming you have some way of

Categories : Image

Using a Colormap with lineplot in matplotlib
I will answer about the colormap. You can use the karg color for specify an rgb color with a tuple... It's well explained in the documentation. "In addition, you can specify colors in many weird and wonderful ways, including full names ('green'), hex strings ('#008000'), RGB or RGBA tuples ((0,1,0,1)) or grayscale intensities as a string ('0.8'). Of these, the string specifications can be used in place of a fmt group, but the tuple forms can be used only as kwargs." Here you have a very simple example: import matplotlib.pyplot as plt import numpy as np x = np.linspace(0,1,1000) n=50 for i in range(1,n): y = i/float(n)*x**2 plt.plot(x,y,color=(i/float(n),(i/float(n))**4,(i/float(n))**2)) ax = plt.gca() ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plt.show()

Categories : Python

Use own colormap in a plot according to a 3rd value (no scatterplot)
There is no buit-in function to do what you want, so I've written a python script to answer your question (the comments explain the code): import matplotlib.pyplot as plt import numpy as np from matplotlib import cm fig = plt.figure() width=4.467 # width in inches of my figure height=4.344 # height in inches of my figure DPI=90 # dots per inch xmin=0 xmax=2*np.pi xx_step=1.0*(xmax-xmin)/(width*DPI) print "xx_step:", xx_step xx=np.arange(xmin, xmax+xx_step, xx_step) ymin=-1 ymax=1 yy_step=1.0*(ymax-ymin)/(height*DPI) print "yy_step:", yy_step yy=np.arange(ymin, ymax+yy_step, yy_step) x_surf, y_surf = np.meshgrid(xx, yy) # generate a mesh z_surf = np.zeros(x_surf.shape)+float('+inf') # to paint with white color the regions that will not contain

Categories : Python

Python: 3D scatter losing colormap
Having modified your code so that it does anything: >>> import numpy as np >>> import matplotlib.pyplot as plt >>> from mpl_toolkits.mplot3d import Axes3D >>> AX = [] >>> fig = plt.figure() >>> ax = fig.add_subplot(111, projection='3d') >>> for R in [range(0,10), range(5,15), range(10,20)]: ... data = [np.array(R), np.array(range(10)), np.array(range(10))] ... AX = ax.scatter(*data, c=data[0], vmin=0, vmax=20, cmap=plt.cm.jet) ... def forceUpdate(event): AX.changed() ... fig.canvas.mpl_connect('draw_event', forceUpdate) ... 9 10 11 >>> plt.colorbar(AX) <matplotlib.colorbar.Colorbar instance at 0x36265a8> >>> plt.show() then I get: So the above code is working. If your existing code isn't t

Categories : Python

How to create a custom colormap programatically
From the docs: A colormap is an m-by-3 matrix of real numbers between 0.0 and 1.0. Each row is an RGB vector that defines one color. The kth row of the colormap defines the kth color, where map(k,:) = [r(k) g(k) b(k)]) specifies the intensity of red, green, and blue. OK so to start we are going to create an m-by-3 matrix, in your case m is 161: m = 161; map = zeros(m , 3); Now you want the bottom to be dark (I'm going with black) and the 50th point to be brown. but lets go with red as an example as it's easier. RGB triples for black and red respectively: [0,0,0] and [1,0,0] OK so currently our enitre colormap is black. We know we want map(50,:) = [1, 0 ,0] i.e. red but now we want a gradient in between right? So lets use linspace for this (note that there is a better method

Categories : Matlab

Make matplotlib colormap from numpy array
From what I gather for every point (x,y) you have two pieces of information, the height and the color. You want to have a surface plot using the height, and colored according to the color at each location. While you can easily specify custom color maps I don't think this will help you. What you are thinking of is not that the same as a colormap which maps the height at (x,y) to a color. The result is most evident in the Surface plots example here I believe what you want is beyond the scope of matplotlib and can only be done with some kind of hack which I doubt you will wish to use. Still here is my suggestion: import pylab as py from mpl_toolkits.mplot3d import Axes3D import numpy as np X = np.arange(-5, 5, 0.1) Y = np.arange(-5, 5, 0.1) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 +

Categories : Python

Python Matplotlib Colorbar/Colormap Settings
You can pass vmin and vmax keyword arguments to plot_surface that specify the value range for your plot: surf = sub.plot_surface(x,y,z,linewidth=0,cmap=cm.coolwarm,vmin=0,vmax=1) See the docs for more info.

Categories : Python

change colormap labels in mayavi/mlab
I don't know of a nice way to do it, but I can think of a hacky one that might well be the easiest thing to do: create an invisible dummy object with the right colormap, and display the colorbar from that object.

Categories : Python

Delete Specific Rows in Matlab
fairly large 2x2 matrix makes little or no sense. This is part from MATLAB documentation You can delete rows and columns from a matrix by assigning the empty array [] to those rows or columns. Start with A = magic(4) A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 Then, delete the second column of A using A(:, 2) = [] This changes matrix A to A = 16 3 13 5 10 8 9 6 12 4 15 1 Also you can delete multiple rows/columns at once: A([1 3],:)=[] A = 5 10 8 4 15 1

Categories : Matlab

Shade the background of matplotlib based on array and colormap
Sure it's possible: x = arange(1,5,0.01) yarr = vstack((x,)) y = sin(x) imshow(yarr, extent=(min(x),max(x), min(y),max(y)), cmap=cm.hot) plot(x, y, color='cornflowerblue',lw=4) The extent keyword matches the limits of the image to the plotted data. This will give you:

Categories : Python

How to use the data matrix to fit the specific 2D-function in matlab
Well,thanks to @Dan.My question seems to be implemented like this: [n,m]=size(d);%assumes that d is a n x m matrix [X,Y]=meshgrid(1:n,1:m);%your x-y coordinates x(:,1)=X(:); % x= first column x(:,2)=Y(:); % y= second column f=d(:); % your data f(x,y) (in column vector) %--- now define the function in terms of x %--- where you use x(:,1)=X and x(:,2)=Y fun = @(c,x) c(1)*sin(pi*(x(:,1)+c(2))).*sin(pi*(x(:,2)+c(3))) ./ (25*sin(pi/5*(x(:,1)+c(2))).*sin(pi/5*(x(:,2)+c(3)))); %--- now solve with lsqcurvefit options=optimset('TolX',1e-6); c0=[1 0 0];%start-guess here cc=lsqcurvefit(fun,c0,x,f,[],[],options); Ifit=fun(cc,x); Ifit=reshape(Ifit,[n m]);%fitting data reshaped as matrix surf(X,Y,Ifit); hold on; plot3(X, Y, dataArray);

Categories : Matlab

Rewriting a function in specific terms with Matlab
You wish to substitute for ONLY some of the x elements in the expression? How do you expect a computer to know what you want? Computers are quite literal things. If you tell it that a = x - 3 then it must also know that x = a + 3 Therefore, f = (a+3)a + 2(a+3)a = 3a(a+3) Only a computer that can read your mind will know that you wish to replace only some of the terms.

Categories : Matlab

How do I make this specific code run faster in Matlab?
Firstly, run the MATLAB profiler (see 'doc profile') and see where the bulk of the execution time is occuring. Secondly, don't update the waitbar on every iteration> Particularly if serial contains a large (> 100) number of elements. Do something like: if (mod(k, 100)==0) % update on every 100th iteration waitbar(k/steps,h,['Please Wait... ' num2str(k/steps*100) ' %']) end

Categories : Arrays

Overwrite only specific fields of a csv file in matlab
Here's a solution based on Marcin's suggestion: datsize = size(a); precision = 6; output_cell = reshape(cellstr(num2str(a(:),precision)), size(a)); for i = 3:datsize(1,1), for j = 3:datsize(1,2), output_textdata(i,j) = output_cell(i-2,j-2); end end cell2csv('foo.csv', output_textdata); While this produces the desired outcome three issues remain. First, the 'precision' varies from cell to cell. Second, which is not a problem for the intended limited application of this script, this code would produce an error if matrix b partially overlapped with matrix a and partially exceeded its dimensions, e.g., b had a size of 4x4 and were superimposed on a starting from a(3,3). Third, this workaround doesn't answer the more general question of whether only specific fields of a csv can be ov

Categories : Matlab

Reading specific column from CSV file in matlab
There are several ways: Using cvsread: Assuming you have N rows in the file1: a = csvread( FILENAME, 0, 1, [0 1 N-1 1 ] ); You might also consider xlsread a = xlsread( FILENAME, 'B:B' ); See specific example on the xlsread doc. Another option is dlmread a = dlmread( FILENAME, ',', [0 1 N-1 1] ); 1 - A nice (and fast) way to count the number of lines in the file in Matlab can be found in this answer by Rody Oldenhuis.

Categories : Matlab

How to choose one specific fgure to plot in Matlab?
Special function figure is used to create new figure graphics objects as well as for selecting some older, already present figure as active for imminent plotting. Function figure and plotting functions (plot, stem etc.) return figure handle of currently active figure that could be used later. Here's an example: fh = figure; % create new figure and save handle in fh plot( ... something ... ); ... When you want to plot to that figure again you should do: figure(fh); plot( ... something else ...);

Categories : Matlab

No signature of method is applicable for argument types: () values: []Possible solutions:(java.lang.Object), (java.lang.Object)
I suspect there's some sort of clash between your explicit addToUserRoles method taking an Object parameter and the implicit one taking a UserRole parameter that GORM adds to support the hasMany declaration. Try using different names for your explicit methods to avoid interfering with GORM, for example List addRole(role){ UserRole.link this, role return roles() } List removeRole(role){ UserRole.unLink this, role return roles() } List addLocation(location){ UserLocation.link this, location return locations() } List removeLocation(location){ UserLocation.unLink this, location return locations() }

Categories : Grails

python matplotlib: how to use fill_between with a colormap to fill the background of a 2d plot?
It sound to me like you should use contourf http://matplotlib.org/examples/pylab_examples/contourf_demo.html This would take x as some dependant variable, produce y = y(x) and z = z(x). It seems that your z is not dependant on y but contourf can still handle this. As a simple example: import pylab as plt x = plt.linspace(0,2,100) y = plt.linspace(0,10,100) z = [[plt.sinc(i) for i in x] for j in y] CS = plt.contourf(x, y, z, 20, # [-1, -0.1, 0, 0.1], cmap=plt.cm.rainbow) plt.colorbar(CS) plt.plot(x,2+plt.sin(y), "--k") The are many variations but hopefully this captures the elements you are looking for

Categories : Python

Import from a specific range of xlsx data in MATLAB GUI
In Matlab, the xlsread function has a parameters where you can specify the sheet and range to read in. http://www.mathworks.com/help/matlab/ref/xlsread.html For the range parameter, you can specify the range just as in excel ex. xlsread('filename', 'A1:B10') to read in the first 10x2 cells. However, I suggest you use Microsoft's VBA language in Matlab to import the data depending how large your excel file. I find this method MUCH MORE efficient for larger data sets. Here is an example of how to use it if you're interested: excelObj = actxserver('Excel.Application'); fileObj = excelObj.Workbooks.Open(filename); sheetObj = fileObj.Worksheets.get('Item', sheetnumber); %Read in ranges the same way as xlsread! indata = sheetObj.Range('A1:B10').Value; I do not have much experience w

Categories : Matlab

Find specific occurances within a vector in MATLAB, without for-loop?
Use intersect: [C, i_vector, i_want] = intersect(vector, want) C is the common elements in both vectors. i_vector would be the common set indices in vector and i_want is the matching set indices in want vector.

Categories : Matlab

MATLAB Plotting dot in a specific area over a contourfm plot
1 Use plotm instead of plot. 2 Replace this line plot(xValue,yValue,'b.','MarkerSize',20); % Plot a black dot with plotm(x(xValue,1),y(1,yValue),'b.','MarkerSize',20); % Plot a black dot Note that find returns the index of the found element not its value. However, in your case you can actually pass the actual values 3 If you will not use xValue and yValue later you can remove these lines xValue = find(x(:,1) == 224); % Longitude closest to 136 03.56W yValue = find(y(1,:) == -66.75); % Latitude closest to 66 39.67S and change the plotting line to plotm(224,-66.75,'b.','MarkerSize',20); % Plot a black dot 4 However this will not plot the dot because the latitude and longitude are swapped comparing to the ranges you have mentioned in axesm command. But since you use co

Categories : Matlab

List of specific files in a directory using `dir` command in matlab
You can use regular expressions in MATLAB to filter out what you want. It's not perfect, but gives decent results. The following code pulls out the 03.dat, 04.dat, 05.dat, 06.dat files: listing = dir('*.dat'); pattern = '0[3-6].dat'; % this is kind of crude, but works: use regexp then pull out all the % non-matching ones with a call to isempty(...) notMatching = cellfun(@isempty, regexp({listing.name}, pattern)) % Pull out the the ones that match: betterListing = listing(~notMatching)

Categories : Matlab

MATLAB: How to make the Hermitean matrix from specific complex vectors?
That's a Toeplitz matrix, you can use the toeplitz command to generate the matrix above. In the general case, this would have been written as: H = toeplitz(kt(N:end), kt(1:N + 1)) where the first N values in kt correspond to k-N, ... k-1, and the last N + 1 values are k0, ... kN. However, since H is Hermitian, this can be simplified to: H = toeplitz(kt(N:end));

Categories : Matlab

Matlab reading from serial port at specific sampling rate
You could try using this before your fscanf statements: while(get(serial_port,'BytesToRead')<2) ; end This will wait until there are two bytes in the serial buffer before you read them. PS: If you are sending numbers you would be better off sending them as numbers rather than as a string - you will need to send three bytes to represent 101 - one for each digit - while this can be sent as a single byte. Use fwrite and fread to do this in Matlab, Serial.write and Serial.read on Arduino.

Categories : Matlab

Matlab: displaying 2D projections with specific color encoding as rgb images in 3D plot
You are calling mapshow with output argument "[~,h2]", but mapshow only returns one output (the handle). So while with contourf this means "don't return contour matrix, do return handle", with mapshow it doesn't make sense. Just replacing [~,h2] with h2 should remove the error you're currently getting.

Categories : Image

How to map ranges of values in MATLAB
you can use linspace, for example linspace(0,1.15,101) will get you 101 points spread uniformly between the limits 0 and 1.15.

Categories : Matlab

Matlab erasing my values
You should listen to Mlint: You are using the class as if it were a reference, but it does not inherit from handle. Quick fix: classdef NaiveClass < handle And then read this: http://www.mathworks.de/de/help/matlab/matlab_oop/comparing-handle-and-value-classes.html

Categories : Matlab

in Matlab, get field values in structs
To copy a nice answer from In Matlab, how can I sort the order of a nested structure? (thanks @Gunther-Struyf!): Points = arrayfun(@(ii) myStruct(ii).travelTime(60,46,75),1:numel(myStruct));

Categories : Matlab



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