Tag Archives: matlab
py.list bug in R2024a
I believe I’m experiencing a bug in R2024a with py.list. After a clear all, I get the error No module or function named ‘list’.:
clear all;res = py.list({"Name1","Name2","Name3"});
In this interface, the code runs just fine. When I run it locally, I get this:
>> clear all;res = py.list({"Name1","Name2","Name3"})
No module or function named ‘list’.
I can get py.list to work again if I use another Python command. For example, this works:
>> handlers = py.logging.getLogger().handlers;
>> res = py.list({"Name1","Name2","Name3"});
>> clear all;res = py.list({"Name1","Name2","Name3"});
No module or function named ‘list’.
I’m running MATLAB Version: 24.1.0.2628055 (R2024a) Update 4. I cannot replicate on R2023b.I believe I’m experiencing a bug in R2024a with py.list. After a clear all, I get the error No module or function named ‘list’.:
clear all;res = py.list({"Name1","Name2","Name3"});
In this interface, the code runs just fine. When I run it locally, I get this:
>> clear all;res = py.list({"Name1","Name2","Name3"})
No module or function named ‘list’.
I can get py.list to work again if I use another Python command. For example, this works:
>> handlers = py.logging.getLogger().handlers;
>> res = py.list({"Name1","Name2","Name3"});
>> clear all;res = py.list({"Name1","Name2","Name3"});
No module or function named ‘list’.
I’m running MATLAB Version: 24.1.0.2628055 (R2024a) Update 4. I cannot replicate on R2023b. I believe I’m experiencing a bug in R2024a with py.list. After a clear all, I get the error No module or function named ‘list’.:
clear all;res = py.list({"Name1","Name2","Name3"});
In this interface, the code runs just fine. When I run it locally, I get this:
>> clear all;res = py.list({"Name1","Name2","Name3"})
No module or function named ‘list’.
I can get py.list to work again if I use another Python command. For example, this works:
>> handlers = py.logging.getLogger().handlers;
>> res = py.list({"Name1","Name2","Name3"});
>> clear all;res = py.list({"Name1","Name2","Name3"});
No module or function named ‘list’.
I’m running MATLAB Version: 24.1.0.2628055 (R2024a) Update 4. I cannot replicate on R2023b. python MATLAB Answers — New Questions
Fit meta data to a custom equation
Hello everyone,
I have been having trouble fitting a set of meta data (attached called IndiMSD) to this custom equation, doing fit to a custom equation and output parameters of the equation.
The first row of data points of x and y is zero, it will output Inf of NaN when do the fit. So I disgard all in x and y matrix.
now the x and y are below:
x_input = readmatrix(‘IndiMSD.xlsx’);
x = x_input(2:end,:); % first zero rows are disgarded, now x is 96 by 112, instead of 97 by 112
y = 15:15:1440;% first zero data point is disgarded, now y is 96 by 1
I want to fit each paif of column of x with y as above. For example, x(:,1) will be fitted with y, output its own S, P value with goodness of fit; , x(:,2) fits with y, output its own S, P value with goodness of fit, and so on until the last column. All fitted results of S, P and goodness of fit will be stored in separate matrice.
The fitted equation is
y = 2*((S^2)*(P^2)) * ((x./P) – 1 + exp(-(x./P)));
I really appreciate it if anyone has some ideas of how to do it.Hello everyone,
I have been having trouble fitting a set of meta data (attached called IndiMSD) to this custom equation, doing fit to a custom equation and output parameters of the equation.
The first row of data points of x and y is zero, it will output Inf of NaN when do the fit. So I disgard all in x and y matrix.
now the x and y are below:
x_input = readmatrix(‘IndiMSD.xlsx’);
x = x_input(2:end,:); % first zero rows are disgarded, now x is 96 by 112, instead of 97 by 112
y = 15:15:1440;% first zero data point is disgarded, now y is 96 by 1
I want to fit each paif of column of x with y as above. For example, x(:,1) will be fitted with y, output its own S, P value with goodness of fit; , x(:,2) fits with y, output its own S, P value with goodness of fit, and so on until the last column. All fitted results of S, P and goodness of fit will be stored in separate matrice.
The fitted equation is
y = 2*((S^2)*(P^2)) * ((x./P) – 1 + exp(-(x./P)));
I really appreciate it if anyone has some ideas of how to do it. Hello everyone,
I have been having trouble fitting a set of meta data (attached called IndiMSD) to this custom equation, doing fit to a custom equation and output parameters of the equation.
The first row of data points of x and y is zero, it will output Inf of NaN when do the fit. So I disgard all in x and y matrix.
now the x and y are below:
x_input = readmatrix(‘IndiMSD.xlsx’);
x = x_input(2:end,:); % first zero rows are disgarded, now x is 96 by 112, instead of 97 by 112
y = 15:15:1440;% first zero data point is disgarded, now y is 96 by 1
I want to fit each paif of column of x with y as above. For example, x(:,1) will be fitted with y, output its own S, P value with goodness of fit; , x(:,2) fits with y, output its own S, P value with goodness of fit, and so on until the last column. All fitted results of S, P and goodness of fit will be stored in separate matrice.
The fitted equation is
y = 2*((S^2)*(P^2)) * ((x./P) – 1 + exp(-(x./P)));
I really appreciate it if anyone has some ideas of how to do it. nonlinear, curve fitting MATLAB Answers — New Questions
VideoReader: Unrecognized function or variable ‘hasFrame’
I am following the VideoReader documentation from https://www.mathworks.com/help/matlab/ref/videoreader.html
When I try to run the example code using R2024a Update 5,
currAxes = axes;
v = VideoReader("xylophone_video.mp4");
while hasFrame(v)
vidFrame = readFrame(v);
image(vidFrame,"Parent",currAxes)
currAxes.Visible = "off";
pause(1/v.FrameRate)
end
the line with while hasFrame(v) throws an error: Unrecognized function or variable ‘hasFrame’.
The VideoReader object was created, but the hasFrame(v) line does not work. Was support for this function removed? If so, what replaced it?I am following the VideoReader documentation from https://www.mathworks.com/help/matlab/ref/videoreader.html
When I try to run the example code using R2024a Update 5,
currAxes = axes;
v = VideoReader("xylophone_video.mp4");
while hasFrame(v)
vidFrame = readFrame(v);
image(vidFrame,"Parent",currAxes)
currAxes.Visible = "off";
pause(1/v.FrameRate)
end
the line with while hasFrame(v) throws an error: Unrecognized function or variable ‘hasFrame’.
The VideoReader object was created, but the hasFrame(v) line does not work. Was support for this function removed? If so, what replaced it? I am following the VideoReader documentation from https://www.mathworks.com/help/matlab/ref/videoreader.html
When I try to run the example code using R2024a Update 5,
currAxes = axes;
v = VideoReader("xylophone_video.mp4");
while hasFrame(v)
vidFrame = readFrame(v);
image(vidFrame,"Parent",currAxes)
currAxes.Visible = "off";
pause(1/v.FrameRate)
end
the line with while hasFrame(v) throws an error: Unrecognized function or variable ‘hasFrame’.
The VideoReader object was created, but the hasFrame(v) line does not work. Was support for this function removed? If so, what replaced it? video processing MATLAB Answers — New Questions
Matlab Custom Add-On disappearing from Add-On list after restarting the Matlab instant
Hi,
I am working with custom Matlab add-on (simulink toolbox) which I tried installing (with/without admin access), but everytime I close the Matlab and reopen the new instance I lose that add-on from add-on list that also mean I am not able to use those custom toolboxes.
Please note I still see the custom add-on installation present on the disk at following folder.
Users<user.name>AppDataRoamingMathWorksMATLAB Add-OnsToolboxes<<CustomToolBox>>
Does anyone know what is the resolution to this?Hi,
I am working with custom Matlab add-on (simulink toolbox) which I tried installing (with/without admin access), but everytime I close the Matlab and reopen the new instance I lose that add-on from add-on list that also mean I am not able to use those custom toolboxes.
Please note I still see the custom add-on installation present on the disk at following folder.
Users<user.name>AppDataRoamingMathWorksMATLAB Add-OnsToolboxes<<CustomToolBox>>
Does anyone know what is the resolution to this? Hi,
I am working with custom Matlab add-on (simulink toolbox) which I tried installing (with/without admin access), but everytime I close the Matlab and reopen the new instance I lose that add-on from add-on list that also mean I am not able to use those custom toolboxes.
Please note I still see the custom add-on installation present on the disk at following folder.
Users<user.name>AppDataRoamingMathWorksMATLAB Add-OnsToolboxes<<CustomToolBox>>
Does anyone know what is the resolution to this? simulink toolbox, add on MATLAB Answers — New Questions
How do I pull data from multiple excel spreadsheets located in the same folder?
Hello!
I’m trying to record a specific data point from multiple excel files that are located in the same folder and dump them into their own table.
To elaborate, I have thousands of excel files all under the path ‘C:UsersMeDataFiles’. I want to open each file, take the data from cell M18, and put it into its own table with all the data points.
I currently have a line using the readmatrix function and I’m able to read just the first file in the folder, but nothing else. I already have a table populated with serial number information, so I get an error that the table variables must have the same number of rows.
Any help would be greatly appreciated, thank you!Hello!
I’m trying to record a specific data point from multiple excel files that are located in the same folder and dump them into their own table.
To elaborate, I have thousands of excel files all under the path ‘C:UsersMeDataFiles’. I want to open each file, take the data from cell M18, and put it into its own table with all the data points.
I currently have a line using the readmatrix function and I’m able to read just the first file in the folder, but nothing else. I already have a table populated with serial number information, so I get an error that the table variables must have the same number of rows.
Any help would be greatly appreciated, thank you! Hello!
I’m trying to record a specific data point from multiple excel files that are located in the same folder and dump them into their own table.
To elaborate, I have thousands of excel files all under the path ‘C:UsersMeDataFiles’. I want to open each file, take the data from cell M18, and put it into its own table with all the data points.
I currently have a line using the readmatrix function and I’m able to read just the first file in the folder, but nothing else. I already have a table populated with serial number information, so I get an error that the table variables must have the same number of rows.
Any help would be greatly appreciated, thank you! importing excel data MATLAB Answers — New Questions
How do I solve the construct marices of multiple variables and plot a graph
I am a beginner to MATLAB.
I tried but I’m getting errors.
Anybody, kindly help. Thank you.
Equations dx/dt=-2x
dy/dt=2x
Initial condition: x(t=0)=100
y(t=0)=0
tspan=[0 3];
x0=100;
y0=0;
dzdt = (dxdt dydt);
[tSol, zSol]=ode45(@odefun,tspan,x0);
plot(tSol, zSol);
function dzdt=odefun(t,z)
x = z(1);
y = z(2);
dxdt = -2*x;
dydt = 2*x;
dzdt = [dxdt;dydt];
endI am a beginner to MATLAB.
I tried but I’m getting errors.
Anybody, kindly help. Thank you.
Equations dx/dt=-2x
dy/dt=2x
Initial condition: x(t=0)=100
y(t=0)=0
tspan=[0 3];
x0=100;
y0=0;
dzdt = (dxdt dydt);
[tSol, zSol]=ode45(@odefun,tspan,x0);
plot(tSol, zSol);
function dzdt=odefun(t,z)
x = z(1);
y = z(2);
dxdt = -2*x;
dydt = 2*x;
dzdt = [dxdt;dydt];
end I am a beginner to MATLAB.
I tried but I’m getting errors.
Anybody, kindly help. Thank you.
Equations dx/dt=-2x
dy/dt=2x
Initial condition: x(t=0)=100
y(t=0)=0
tspan=[0 3];
x0=100;
y0=0;
dzdt = (dxdt dydt);
[tSol, zSol]=ode45(@odefun,tspan,x0);
plot(tSol, zSol);
function dzdt=odefun(t,z)
x = z(1);
y = z(2);
dxdt = -2*x;
dydt = 2*x;
dzdt = [dxdt;dydt];
end ode MATLAB Answers — New Questions
background image with know cords not scaling properly when same grid values are assigned in Matplotlib python
I have a map. On this map i have known x,y positions and the know origin value (1,1) and max value(419,419). when given into matlablip i get very close to accurate values at the center of the map but near the top and bottom they vary by 5 or 6 units. almost the like image is being gently stretched from the middle out. i assume this is to bind it the the grid size.
My map image is 2048×2048 pixels. and i am constraining the map to a 419×419 grid. I’m assuming that due to the way its scaling the image im getting this strech but i’m unable to see what settings might fix this.
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import os
from matplotlib.patches import Rectangle
from matplotlib.widgets import Button
# Directory path
dir_path = ‘MY_DIR/’
# Load background image
print("Loading background image…")
background_image_path = os.path.join(dir_path, ‘MY_IMAGE’)
background_image = Image.open(background_image_path)
# Load grid size and offsets from file
print("Loading grid size, obstacle offset, and image offset…")
size_file_path = os.path.join(dir_path, ‘size.txt’)
with open(size_file_path, ‘r’) as file:
grid_size_x, grid_size_y = map(int, file.readline().strip().split(‘,’))
obstacle_offset_x, obstacle_offset_y = map(float, file.readline().strip().split(‘,’))
image_offset_x, image_offset_y = map(float, file.readline().strip().split(‘,’))
print(f"Grid size: {grid_size_x}, {grid_size_y}")
print(f"Obstacle offset: {obstacle_offset_x}, {obstacle_offset_y}")
print(f"Image offset: {image_offset_x}, {image_offset_y}")
# Function to load obstacles from B&W image
def load_obstacles_from_image(image_path, grid_size_x, grid_size_y):
print("Loading obstacles from B&W image…")
bw_image = Image.open(image_path).convert(‘L’)
bw_image = bw_image.resize((grid_size_x, grid_size_y))
bw_array = np.array(bw_image)
obstacles = []
for y in range(grid_size_y):
for x in range(grid_size_x):
if bw_array[y, x] < 128: # Assuming obstacles are black (value < 128)
obstacles.append((x + 1, y + 1)) # Adjust for grid origin (1,1)
return list(set((round(x), round(y)) for x, y in obstacles))
# Function to validate if obstacles file contains valid coordinates
def validate_obstacles_file(file_path):
with open(file_path, ‘r’) as file:
for line in file:
if line.strip():
try:
x, y = map(int, line.strip().split(‘,’))
except ValueError:
return False
return True
# Load obstacles from file or image
obstacle_file_path = os.path.join(dir_path, ‘obstacles.txt’)
if os.path.exists(obstacle_file_path) and validate_obstacles_file(obstacle_file_path):
print("Loading obstacles from obstacles.txt…")
with open(obstacle_file_path, ‘r’) as file:
obstacles = [tuple(map(int, line.strip().split(‘,’))) for line in file if line.strip()]
else:
obstacles = load_obstacles_from_image(os.path.join(dir_path, ‘obstacles_bw.png’), grid_size_x, grid_size_y)
with open(obstacle_file_path, ‘w’) as file:
for x, y in obstacles:
file.write(f"{x},{y}n")
print(f"Loaded {len(obstacles)} obstacles")
# Apply obstacle offset
obstacles = [(x + obstacle_offset_x, y + obstacle_offset_y) for x, y in obstacles]
# Load points of interest (POI) from file
print("Loading points of interest…")
poi_file_path = os.path.join(dir_path, ‘poi.txt’)
poi_points = []
with open(poi_file_path, ‘r’) as file:
for line in file:
x, y = map(float, line.strip().split(‘,’))
poi_points.append((x, y))
print(f"Loaded {len(poi_points)} points of interest (POI)")
# Create maze for pathfinding
def create_maze(grid_size_x, grid_size_y, obstacles):
print("Creating maze…")
maze = np.zeros((grid_size_y + 1, grid_size_x + 1)) # Adjust for grid origin (1,1)
for x, y in obstacles:
maze[int(y)][int(x)] = 1
return maze
maze = create_maze(grid_size_x, grid_size_y, obstacles)
print("Maze created.")
print("Maze obstacles:")
print(np.argwhere(maze == 1))
# A* pathfinding algorithm
class Node:
def __init__(self, parent=None, position=None):
self.parent = parent
self.position = position
self.g = 0
self.h = 0
self.f = 0
def __eq__(self, other):
return self.position == other.position
def astar(maze, start, end):
print("Starting A* algorithm…")
start_node = Node(None, start)
end_node = Node(None, end)
open_list = []
closed_list = []
open_list.append(start_node)
iterations = 0
max_iterations = 10000 # Limit iterations for debugging
while open_list:
iterations += 1
if iterations > max_iterations:
print("Reached maximum iterations, stopping to avoid infinite loop.")
break
# Get the current node
current_node = open_list[0]
current_index = 0
for index, item in enumerate(open_list):
if item.f < current_node.f:
current_node = item
current_index = index
# Pop current off open list, add to closed list
open_list.pop(current_index)
closed_list.append(current_node)
# Found the goal
if current_node == end_node:
path = []
current = current_node
while current is not None:
path.append(current.position)
current = current.parent
print("Path found.")
return path[::-1] # Return reversed path
# Generate children
children = []
for new_position in [(0, -1), (0, 1), (-1, 0), (1, 0), (-1, -1), (-1, 1), (1, -1), (1, 1)]: # Adjacent squares
# Get node position
node_position = (current_node.position[0] + new_position[0], current_node.position[1] + new_position[1])
# Make sure within range
if node_position[0] > (len(maze) – 1) or node_position[0] < 0 or node_position[1] > (len(maze[len(maze) – 1]) – 1) or node_position[1] < 0:
continue
# Make sure walkable terrain
if maze[node_position[1]][node_position[0]] != 0: # Note the inversion of indices here
continue
# Create new node
new_node = Node(current_node, node_position)
# Append
children.append(new_node)
# Loop through children
for child in children:
# Child is on the closed list
if child in closed_list:
continue
# Create the f, g, and h values
child.g = current_node.g + 1
child.h = ((child.position[0] – end_node.position[0]) ** 2) + ((child.position[1] – end_node.position[1]) ** 2)
child.f = child.g + child.h
# Child is already in the open list
if any(open_node for open_node in open_list if child == open_node and child.g > open_node.g):
continue
# Add the child to the open list
open_list.append(child)
if iterations % 1000 == 0:
print(f"Iteration {iterations}: Open list size: {len(open_list)}, Closed list size: {len(closed_list)}")
print("No path found.")
return []
def plot_path(ax, path):
if path:
path_x, path_y = zip(*path)
ax.plot(path_x, path_y, color=’blue’, linewidth=2, label=’Path’)
# Initial start and end points for testing
start_point = (255, 233)
end_point = (240, 240)
start_point_maze = (int(start_point[0]), int(start_point[1])) # Adjust for maze coordinates
end_point_maze = (int(end_point[0]), int(end_point[1])) # Adjust for maze coordinates
print(f"Running A* from {start_point_maze} to {end_point_maze}…")
path = astar(maze, start_point_maze, end_point_maze)
# Plot the results
print("Plotting results…")
fig, ax = plt.subplots(figsize=(10, 10))
ax.imshow(background_image, extent=[image_offset_x, grid_size_x + image_offset_x, grid_size_y + image_offset_y, image_offset_y], origin=’upper’)
obstacles_patches = [] # List to store obstacle patches
if obstacles:
for (x, y) in obstacles:
rect = Rectangle((x – 0.25, y – 0.25), 0.5, 0.5, linewidth=1, edgecolor=’red’, facecolor=’red’)
obstacles_patches.append(rect)
ax.add_patch(rect)
if poi_points:
px, py = zip(*poi_points)
ax.scatter(px, py, c=’blue’, s=10, label=’POIs’)
plot_path(ax, path)
ax.scatter(start_point[0], start_point[1], c=’green’, s=50, label=’Start’)
ax.scatter(end_point[0], end_point[1], c=’purple’, s=50, label=’End’)
ax.set_title(‘Background Image with Obstacles, POIs, and Path’)
ax.legend()
# Toggle obstacles visibility
def toggle_obstacles(event):
for patch in obstacles_patches:
patch.set_visible(not patch.get_visible())
plt.draw()
# Add button to toggle obstacles
ax_button = plt.axes([0.8, 0.05, 0.1, 0.075])
button = Button(ax_button, ‘Toggle Obstacles’)
button.on_clicked(toggle_obstacles)
plt.show()
print("Finished plotting.")I have a map. On this map i have known x,y positions and the know origin value (1,1) and max value(419,419). when given into matlablip i get very close to accurate values at the center of the map but near the top and bottom they vary by 5 or 6 units. almost the like image is being gently stretched from the middle out. i assume this is to bind it the the grid size.
My map image is 2048×2048 pixels. and i am constraining the map to a 419×419 grid. I’m assuming that due to the way its scaling the image im getting this strech but i’m unable to see what settings might fix this.
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import os
from matplotlib.patches import Rectangle
from matplotlib.widgets import Button
# Directory path
dir_path = ‘MY_DIR/’
# Load background image
print("Loading background image…")
background_image_path = os.path.join(dir_path, ‘MY_IMAGE’)
background_image = Image.open(background_image_path)
# Load grid size and offsets from file
print("Loading grid size, obstacle offset, and image offset…")
size_file_path = os.path.join(dir_path, ‘size.txt’)
with open(size_file_path, ‘r’) as file:
grid_size_x, grid_size_y = map(int, file.readline().strip().split(‘,’))
obstacle_offset_x, obstacle_offset_y = map(float, file.readline().strip().split(‘,’))
image_offset_x, image_offset_y = map(float, file.readline().strip().split(‘,’))
print(f"Grid size: {grid_size_x}, {grid_size_y}")
print(f"Obstacle offset: {obstacle_offset_x}, {obstacle_offset_y}")
print(f"Image offset: {image_offset_x}, {image_offset_y}")
# Function to load obstacles from B&W image
def load_obstacles_from_image(image_path, grid_size_x, grid_size_y):
print("Loading obstacles from B&W image…")
bw_image = Image.open(image_path).convert(‘L’)
bw_image = bw_image.resize((grid_size_x, grid_size_y))
bw_array = np.array(bw_image)
obstacles = []
for y in range(grid_size_y):
for x in range(grid_size_x):
if bw_array[y, x] < 128: # Assuming obstacles are black (value < 128)
obstacles.append((x + 1, y + 1)) # Adjust for grid origin (1,1)
return list(set((round(x), round(y)) for x, y in obstacles))
# Function to validate if obstacles file contains valid coordinates
def validate_obstacles_file(file_path):
with open(file_path, ‘r’) as file:
for line in file:
if line.strip():
try:
x, y = map(int, line.strip().split(‘,’))
except ValueError:
return False
return True
# Load obstacles from file or image
obstacle_file_path = os.path.join(dir_path, ‘obstacles.txt’)
if os.path.exists(obstacle_file_path) and validate_obstacles_file(obstacle_file_path):
print("Loading obstacles from obstacles.txt…")
with open(obstacle_file_path, ‘r’) as file:
obstacles = [tuple(map(int, line.strip().split(‘,’))) for line in file if line.strip()]
else:
obstacles = load_obstacles_from_image(os.path.join(dir_path, ‘obstacles_bw.png’), grid_size_x, grid_size_y)
with open(obstacle_file_path, ‘w’) as file:
for x, y in obstacles:
file.write(f"{x},{y}n")
print(f"Loaded {len(obstacles)} obstacles")
# Apply obstacle offset
obstacles = [(x + obstacle_offset_x, y + obstacle_offset_y) for x, y in obstacles]
# Load points of interest (POI) from file
print("Loading points of interest…")
poi_file_path = os.path.join(dir_path, ‘poi.txt’)
poi_points = []
with open(poi_file_path, ‘r’) as file:
for line in file:
x, y = map(float, line.strip().split(‘,’))
poi_points.append((x, y))
print(f"Loaded {len(poi_points)} points of interest (POI)")
# Create maze for pathfinding
def create_maze(grid_size_x, grid_size_y, obstacles):
print("Creating maze…")
maze = np.zeros((grid_size_y + 1, grid_size_x + 1)) # Adjust for grid origin (1,1)
for x, y in obstacles:
maze[int(y)][int(x)] = 1
return maze
maze = create_maze(grid_size_x, grid_size_y, obstacles)
print("Maze created.")
print("Maze obstacles:")
print(np.argwhere(maze == 1))
# A* pathfinding algorithm
class Node:
def __init__(self, parent=None, position=None):
self.parent = parent
self.position = position
self.g = 0
self.h = 0
self.f = 0
def __eq__(self, other):
return self.position == other.position
def astar(maze, start, end):
print("Starting A* algorithm…")
start_node = Node(None, start)
end_node = Node(None, end)
open_list = []
closed_list = []
open_list.append(start_node)
iterations = 0
max_iterations = 10000 # Limit iterations for debugging
while open_list:
iterations += 1
if iterations > max_iterations:
print("Reached maximum iterations, stopping to avoid infinite loop.")
break
# Get the current node
current_node = open_list[0]
current_index = 0
for index, item in enumerate(open_list):
if item.f < current_node.f:
current_node = item
current_index = index
# Pop current off open list, add to closed list
open_list.pop(current_index)
closed_list.append(current_node)
# Found the goal
if current_node == end_node:
path = []
current = current_node
while current is not None:
path.append(current.position)
current = current.parent
print("Path found.")
return path[::-1] # Return reversed path
# Generate children
children = []
for new_position in [(0, -1), (0, 1), (-1, 0), (1, 0), (-1, -1), (-1, 1), (1, -1), (1, 1)]: # Adjacent squares
# Get node position
node_position = (current_node.position[0] + new_position[0], current_node.position[1] + new_position[1])
# Make sure within range
if node_position[0] > (len(maze) – 1) or node_position[0] < 0 or node_position[1] > (len(maze[len(maze) – 1]) – 1) or node_position[1] < 0:
continue
# Make sure walkable terrain
if maze[node_position[1]][node_position[0]] != 0: # Note the inversion of indices here
continue
# Create new node
new_node = Node(current_node, node_position)
# Append
children.append(new_node)
# Loop through children
for child in children:
# Child is on the closed list
if child in closed_list:
continue
# Create the f, g, and h values
child.g = current_node.g + 1
child.h = ((child.position[0] – end_node.position[0]) ** 2) + ((child.position[1] – end_node.position[1]) ** 2)
child.f = child.g + child.h
# Child is already in the open list
if any(open_node for open_node in open_list if child == open_node and child.g > open_node.g):
continue
# Add the child to the open list
open_list.append(child)
if iterations % 1000 == 0:
print(f"Iteration {iterations}: Open list size: {len(open_list)}, Closed list size: {len(closed_list)}")
print("No path found.")
return []
def plot_path(ax, path):
if path:
path_x, path_y = zip(*path)
ax.plot(path_x, path_y, color=’blue’, linewidth=2, label=’Path’)
# Initial start and end points for testing
start_point = (255, 233)
end_point = (240, 240)
start_point_maze = (int(start_point[0]), int(start_point[1])) # Adjust for maze coordinates
end_point_maze = (int(end_point[0]), int(end_point[1])) # Adjust for maze coordinates
print(f"Running A* from {start_point_maze} to {end_point_maze}…")
path = astar(maze, start_point_maze, end_point_maze)
# Plot the results
print("Plotting results…")
fig, ax = plt.subplots(figsize=(10, 10))
ax.imshow(background_image, extent=[image_offset_x, grid_size_x + image_offset_x, grid_size_y + image_offset_y, image_offset_y], origin=’upper’)
obstacles_patches = [] # List to store obstacle patches
if obstacles:
for (x, y) in obstacles:
rect = Rectangle((x – 0.25, y – 0.25), 0.5, 0.5, linewidth=1, edgecolor=’red’, facecolor=’red’)
obstacles_patches.append(rect)
ax.add_patch(rect)
if poi_points:
px, py = zip(*poi_points)
ax.scatter(px, py, c=’blue’, s=10, label=’POIs’)
plot_path(ax, path)
ax.scatter(start_point[0], start_point[1], c=’green’, s=50, label=’Start’)
ax.scatter(end_point[0], end_point[1], c=’purple’, s=50, label=’End’)
ax.set_title(‘Background Image with Obstacles, POIs, and Path’)
ax.legend()
# Toggle obstacles visibility
def toggle_obstacles(event):
for patch in obstacles_patches:
patch.set_visible(not patch.get_visible())
plt.draw()
# Add button to toggle obstacles
ax_button = plt.axes([0.8, 0.05, 0.1, 0.075])
button = Button(ax_button, ‘Toggle Obstacles’)
button.on_clicked(toggle_obstacles)
plt.show()
print("Finished plotting.") I have a map. On this map i have known x,y positions and the know origin value (1,1) and max value(419,419). when given into matlablip i get very close to accurate values at the center of the map but near the top and bottom they vary by 5 or 6 units. almost the like image is being gently stretched from the middle out. i assume this is to bind it the the grid size.
My map image is 2048×2048 pixels. and i am constraining the map to a 419×419 grid. I’m assuming that due to the way its scaling the image im getting this strech but i’m unable to see what settings might fix this.
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import os
from matplotlib.patches import Rectangle
from matplotlib.widgets import Button
# Directory path
dir_path = ‘MY_DIR/’
# Load background image
print("Loading background image…")
background_image_path = os.path.join(dir_path, ‘MY_IMAGE’)
background_image = Image.open(background_image_path)
# Load grid size and offsets from file
print("Loading grid size, obstacle offset, and image offset…")
size_file_path = os.path.join(dir_path, ‘size.txt’)
with open(size_file_path, ‘r’) as file:
grid_size_x, grid_size_y = map(int, file.readline().strip().split(‘,’))
obstacle_offset_x, obstacle_offset_y = map(float, file.readline().strip().split(‘,’))
image_offset_x, image_offset_y = map(float, file.readline().strip().split(‘,’))
print(f"Grid size: {grid_size_x}, {grid_size_y}")
print(f"Obstacle offset: {obstacle_offset_x}, {obstacle_offset_y}")
print(f"Image offset: {image_offset_x}, {image_offset_y}")
# Function to load obstacles from B&W image
def load_obstacles_from_image(image_path, grid_size_x, grid_size_y):
print("Loading obstacles from B&W image…")
bw_image = Image.open(image_path).convert(‘L’)
bw_image = bw_image.resize((grid_size_x, grid_size_y))
bw_array = np.array(bw_image)
obstacles = []
for y in range(grid_size_y):
for x in range(grid_size_x):
if bw_array[y, x] < 128: # Assuming obstacles are black (value < 128)
obstacles.append((x + 1, y + 1)) # Adjust for grid origin (1,1)
return list(set((round(x), round(y)) for x, y in obstacles))
# Function to validate if obstacles file contains valid coordinates
def validate_obstacles_file(file_path):
with open(file_path, ‘r’) as file:
for line in file:
if line.strip():
try:
x, y = map(int, line.strip().split(‘,’))
except ValueError:
return False
return True
# Load obstacles from file or image
obstacle_file_path = os.path.join(dir_path, ‘obstacles.txt’)
if os.path.exists(obstacle_file_path) and validate_obstacles_file(obstacle_file_path):
print("Loading obstacles from obstacles.txt…")
with open(obstacle_file_path, ‘r’) as file:
obstacles = [tuple(map(int, line.strip().split(‘,’))) for line in file if line.strip()]
else:
obstacles = load_obstacles_from_image(os.path.join(dir_path, ‘obstacles_bw.png’), grid_size_x, grid_size_y)
with open(obstacle_file_path, ‘w’) as file:
for x, y in obstacles:
file.write(f"{x},{y}n")
print(f"Loaded {len(obstacles)} obstacles")
# Apply obstacle offset
obstacles = [(x + obstacle_offset_x, y + obstacle_offset_y) for x, y in obstacles]
# Load points of interest (POI) from file
print("Loading points of interest…")
poi_file_path = os.path.join(dir_path, ‘poi.txt’)
poi_points = []
with open(poi_file_path, ‘r’) as file:
for line in file:
x, y = map(float, line.strip().split(‘,’))
poi_points.append((x, y))
print(f"Loaded {len(poi_points)} points of interest (POI)")
# Create maze for pathfinding
def create_maze(grid_size_x, grid_size_y, obstacles):
print("Creating maze…")
maze = np.zeros((grid_size_y + 1, grid_size_x + 1)) # Adjust for grid origin (1,1)
for x, y in obstacles:
maze[int(y)][int(x)] = 1
return maze
maze = create_maze(grid_size_x, grid_size_y, obstacles)
print("Maze created.")
print("Maze obstacles:")
print(np.argwhere(maze == 1))
# A* pathfinding algorithm
class Node:
def __init__(self, parent=None, position=None):
self.parent = parent
self.position = position
self.g = 0
self.h = 0
self.f = 0
def __eq__(self, other):
return self.position == other.position
def astar(maze, start, end):
print("Starting A* algorithm…")
start_node = Node(None, start)
end_node = Node(None, end)
open_list = []
closed_list = []
open_list.append(start_node)
iterations = 0
max_iterations = 10000 # Limit iterations for debugging
while open_list:
iterations += 1
if iterations > max_iterations:
print("Reached maximum iterations, stopping to avoid infinite loop.")
break
# Get the current node
current_node = open_list[0]
current_index = 0
for index, item in enumerate(open_list):
if item.f < current_node.f:
current_node = item
current_index = index
# Pop current off open list, add to closed list
open_list.pop(current_index)
closed_list.append(current_node)
# Found the goal
if current_node == end_node:
path = []
current = current_node
while current is not None:
path.append(current.position)
current = current.parent
print("Path found.")
return path[::-1] # Return reversed path
# Generate children
children = []
for new_position in [(0, -1), (0, 1), (-1, 0), (1, 0), (-1, -1), (-1, 1), (1, -1), (1, 1)]: # Adjacent squares
# Get node position
node_position = (current_node.position[0] + new_position[0], current_node.position[1] + new_position[1])
# Make sure within range
if node_position[0] > (len(maze) – 1) or node_position[0] < 0 or node_position[1] > (len(maze[len(maze) – 1]) – 1) or node_position[1] < 0:
continue
# Make sure walkable terrain
if maze[node_position[1]][node_position[0]] != 0: # Note the inversion of indices here
continue
# Create new node
new_node = Node(current_node, node_position)
# Append
children.append(new_node)
# Loop through children
for child in children:
# Child is on the closed list
if child in closed_list:
continue
# Create the f, g, and h values
child.g = current_node.g + 1
child.h = ((child.position[0] – end_node.position[0]) ** 2) + ((child.position[1] – end_node.position[1]) ** 2)
child.f = child.g + child.h
# Child is already in the open list
if any(open_node for open_node in open_list if child == open_node and child.g > open_node.g):
continue
# Add the child to the open list
open_list.append(child)
if iterations % 1000 == 0:
print(f"Iteration {iterations}: Open list size: {len(open_list)}, Closed list size: {len(closed_list)}")
print("No path found.")
return []
def plot_path(ax, path):
if path:
path_x, path_y = zip(*path)
ax.plot(path_x, path_y, color=’blue’, linewidth=2, label=’Path’)
# Initial start and end points for testing
start_point = (255, 233)
end_point = (240, 240)
start_point_maze = (int(start_point[0]), int(start_point[1])) # Adjust for maze coordinates
end_point_maze = (int(end_point[0]), int(end_point[1])) # Adjust for maze coordinates
print(f"Running A* from {start_point_maze} to {end_point_maze}…")
path = astar(maze, start_point_maze, end_point_maze)
# Plot the results
print("Plotting results…")
fig, ax = plt.subplots(figsize=(10, 10))
ax.imshow(background_image, extent=[image_offset_x, grid_size_x + image_offset_x, grid_size_y + image_offset_y, image_offset_y], origin=’upper’)
obstacles_patches = [] # List to store obstacle patches
if obstacles:
for (x, y) in obstacles:
rect = Rectangle((x – 0.25, y – 0.25), 0.5, 0.5, linewidth=1, edgecolor=’red’, facecolor=’red’)
obstacles_patches.append(rect)
ax.add_patch(rect)
if poi_points:
px, py = zip(*poi_points)
ax.scatter(px, py, c=’blue’, s=10, label=’POIs’)
plot_path(ax, path)
ax.scatter(start_point[0], start_point[1], c=’green’, s=50, label=’Start’)
ax.scatter(end_point[0], end_point[1], c=’purple’, s=50, label=’End’)
ax.set_title(‘Background Image with Obstacles, POIs, and Path’)
ax.legend()
# Toggle obstacles visibility
def toggle_obstacles(event):
for patch in obstacles_patches:
patch.set_visible(not patch.get_visible())
plt.draw()
# Add button to toggle obstacles
ax_button = plt.axes([0.8, 0.05, 0.1, 0.075])
button = Button(ax_button, ‘Toggle Obstacles’)
button.on_clicked(toggle_obstacles)
plt.show()
print("Finished plotting.") python, discrete, quantization, map image MATLAB Answers — New Questions
When VS initializes the library generated by calling Matlab, the following problem occurs and the application crashes.
Hello expert, I would like to ask if Matlab2015b (32-bit) is compatible with vs2013(32-bit), the problem I am having now is that when I generate the corresponding .lib.h.dll.crf with Matlab, I call it with vs2013, but when it comes to initializing the loading library I generated, the application somehow jumps out. Prompt:
First-chance exception at 0x7695A782 in MfdPrj.exe: Microsoft C++ exception: MathWorks::System::SimpleException at memory location 0x4C0FD8AC.
First-chance exception at 0x7695A782 in MfdPrj.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
and the following questions are asked
Ask the great god for guidanceHello expert, I would like to ask if Matlab2015b (32-bit) is compatible with vs2013(32-bit), the problem I am having now is that when I generate the corresponding .lib.h.dll.crf with Matlab, I call it with vs2013, but when it comes to initializing the loading library I generated, the application somehow jumps out. Prompt:
First-chance exception at 0x7695A782 in MfdPrj.exe: Microsoft C++ exception: MathWorks::System::SimpleException at memory location 0x4C0FD8AC.
First-chance exception at 0x7695A782 in MfdPrj.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
and the following questions are asked
Ask the great god for guidance Hello expert, I would like to ask if Matlab2015b (32-bit) is compatible with vs2013(32-bit), the problem I am having now is that when I generate the corresponding .lib.h.dll.crf with Matlab, I call it with vs2013, but when it comes to initializing the loading library I generated, the application somehow jumps out. Prompt:
First-chance exception at 0x7695A782 in MfdPrj.exe: Microsoft C++ exception: MathWorks::System::SimpleException at memory location 0x4C0FD8AC.
First-chance exception at 0x7695A782 in MfdPrj.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
and the following questions are asked
Ask the great god for guidance matlab c++ myprojectinitialize() MATLAB Answers — New Questions
Minimizing MATLAB windows while running?
In my code, series of images are being processed and at each stage I have to show different figures in several windows, but as you know while running each window comes up and prevents you from doing your other things with your PC while running.
Is it possible to ask MATLAB to minimize all the windows (while running), so that the user can do his other things meanwhile?
Thanks so much.
StevenIn my code, series of images are being processed and at each stage I have to show different figures in several windows, but as you know while running each window comes up and prevents you from doing your other things with your PC while running.
Is it possible to ask MATLAB to minimize all the windows (while running), so that the user can do his other things meanwhile?
Thanks so much.
Steven In my code, series of images are being processed and at each stage I have to show different figures in several windows, but as you know while running each window comes up and prevents you from doing your other things with your PC while running.
Is it possible to ask MATLAB to minimize all the windows (while running), so that the user can do his other things meanwhile?
Thanks so much.
Steven minimizing, image series MATLAB Answers — New Questions
CAN Explorer and I/O 602 Speedgoat module
How do I connect my speedgoat module I/O602 and read data bus on CAN Explorer?
I refresh all hardwares available and only MathWorks virtual are listed.How do I connect my speedgoat module I/O602 and read data bus on CAN Explorer?
I refresh all hardwares available and only MathWorks virtual are listed. How do I connect my speedgoat module I/O602 and read data bus on CAN Explorer?
I refresh all hardwares available and only MathWorks virtual are listed. can, speedgoat, io602 MATLAB Answers — New Questions
adapt histogram equalization- clahe
I have a problem with the final interpolation I think. the connection between the tiles is very visible and each tile has a different colloring.
Any one have an idea how i can make this better?I have a problem with the final interpolation I think. the connection between the tiles is very visible and each tile has a different colloring.
Any one have an idea how i can make this better? I have a problem with the final interpolation I think. the connection between the tiles is very visible and each tile has a different colloring.
Any one have an idea how i can make this better? intrepolation MATLAB Answers — New Questions
Unrecognized function or variable ‘graphconncomp’.
The original code is this. I cannot find the addon containing the graphconncomp function. Error in moseg.MosegAlgAffBase/evalsplit2 (line 389) The line of code accessing it is:
% First find connected components
[S,C] = graphconncomp(Wceps);
There is a potential alternative using the GPToolBox . However when using this function I get a different error:
Incorrect number or types of inputs or outputs for function conncomp.
Error in moseg.MosegAlgAffBase/evalsplit2 (line 413)
[S,C] = conncomp(Wceps);
If there a distribuion of Matlab I should use, or a specific package? (I used AddOn package search also).The original code is this. I cannot find the addon containing the graphconncomp function. Error in moseg.MosegAlgAffBase/evalsplit2 (line 389) The line of code accessing it is:
% First find connected components
[S,C] = graphconncomp(Wceps);
There is a potential alternative using the GPToolBox . However when using this function I get a different error:
Incorrect number or types of inputs or outputs for function conncomp.
Error in moseg.MosegAlgAffBase/evalsplit2 (line 413)
[S,C] = conncomp(Wceps);
If there a distribuion of Matlab I should use, or a specific package? (I used AddOn package search also). The original code is this. I cannot find the addon containing the graphconncomp function. Error in moseg.MosegAlgAffBase/evalsplit2 (line 389) The line of code accessing it is:
% First find connected components
[S,C] = graphconncomp(Wceps);
There is a potential alternative using the GPToolBox . However when using this function I get a different error:
Incorrect number or types of inputs or outputs for function conncomp.
Error in moseg.MosegAlgAffBase/evalsplit2 (line 413)
[S,C] = conncomp(Wceps);
If there a distribuion of Matlab I should use, or a specific package? (I used AddOn package search also). image segmenation, motion segmentation, graph, connected components MATLAB Answers — New Questions
我不懂這是什麼意思
>> unzip(‘MerchData.zip’);pwd
Warning: Permission denied to create file "MerchData".
> In unzip (line 103)>> unzip(‘MerchData.zip’);pwd
Warning: Permission denied to create file "MerchData".
> In unzip (line 103) >> unzip(‘MerchData.zip’);pwd
Warning: Permission denied to create file "MerchData".
> In unzip (line 103) deep learning MATLAB Answers — New Questions
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing symbolic variables into double array. Apply ‘subs’ function first to substitute values for variables.
Hi! I am trying to plot a fourier function by using fplot but I am getting the following error.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing symbolic variables into double array.
Apply ‘subs’ function first to substitute values for variables.
syms f(t) g(t) w;
x=@(t)heaviside(exp(-20*t));
h=@(t) heaviside(12.*t.*exp(55*t));
xf=vpa(fourier(f,t,w));
hf=vpa(fourier(g,t,w));
fplot(@(w) abs(hf), [-20*pi 20*pi])Hi! I am trying to plot a fourier function by using fplot but I am getting the following error.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing symbolic variables into double array.
Apply ‘subs’ function first to substitute values for variables.
syms f(t) g(t) w;
x=@(t)heaviside(exp(-20*t));
h=@(t) heaviside(12.*t.*exp(55*t));
xf=vpa(fourier(f,t,w));
hf=vpa(fourier(g,t,w));
fplot(@(w) abs(hf), [-20*pi 20*pi]) Hi! I am trying to plot a fourier function by using fplot but I am getting the following error.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing symbolic variables into double array.
Apply ‘subs’ function first to substitute values for variables.
syms f(t) g(t) w;
x=@(t)heaviside(exp(-20*t));
h=@(t) heaviside(12.*t.*exp(55*t));
xf=vpa(fourier(f,t,w));
hf=vpa(fourier(g,t,w));
fplot(@(w) abs(hf), [-20*pi 20*pi]) fplot MATLAB Answers — New Questions
What is the Legacy version of Matlab ?
I want to know legacy version of Matlab !I want to know legacy version of Matlab ! I want to know legacy version of Matlab ! legacy versions MATLAB Answers — New Questions
A MATLAB license for an individual researcher
Hi,
Since I faced some non-consistent answers in relevant MathWorks forums [1-3] I would like to clarify a few doubts I have regarding MATLAB licensing. I defended my PhD two years ago. As of now, I am no longer associated with any university or company using MATLAB. As a hobbyist, in my spare time I work individually on some non-commercial computer science research projects. I plan to publish the obtained simulation results and parts of MATLAB code in two research papers and a book (containing my PhD thesis with minor improvements).
Is the MATLAB Home license sufficient for my needs? The commercial license seems way too expensive and irrelevant in this case (not earning money), and for the academic license, I guess I would need to be an "degree-granting institute" which I am not. I would also like to avoid rewriting all scripts I wrote during my PhD research to Python or Octave.
What is the actual MATLAB usage covered in licenses? Some time ago on the MATLAB website https://www.mathworks.com/pricing-licensing.html?prodcode=ML&intendeduse=home it was mentioned that one was not able to do research and publish results using MATLAB Home. I can’t see this note anymore. Now there is only "For personal use only. This license option is not for government, academic, commercial, or other organizational use". So, can I publish results (e.g. using the MATLAB plots)? Or can I publish MATLAB code only? Or can I only run such code? I can find plenty of blogs with hobbysts’ projects in the Internet using MATLAB, fully documented, so the "hobbyist" term remains not clear to me. For instance, if I write a C++ library under the Apache/MIT license which do some FFT computations under the hood, will I be able to use MATLAB Home just to verify solutions numerically?
Sincerely,
Mariusz M.
[1] https://www.mathworks.com/matlabcentral/answers/376174-how-to-get-permission-to-publish-my-matlab-programs
[2] https://www.mathworks.com/matlabcentral/answers/388329-what-a-license-i-need-to-publish-my-program-in-an-internet-site?s_tid=answers_rc1-3_p3_Topic
[3] https://www.mathworks.com/matlabcentral/answers/349000-does-a-home-license-allow-for-research-and-publishing-results-technical-papers-as-an-individual-o#answer_274396Hi,
Since I faced some non-consistent answers in relevant MathWorks forums [1-3] I would like to clarify a few doubts I have regarding MATLAB licensing. I defended my PhD two years ago. As of now, I am no longer associated with any university or company using MATLAB. As a hobbyist, in my spare time I work individually on some non-commercial computer science research projects. I plan to publish the obtained simulation results and parts of MATLAB code in two research papers and a book (containing my PhD thesis with minor improvements).
Is the MATLAB Home license sufficient for my needs? The commercial license seems way too expensive and irrelevant in this case (not earning money), and for the academic license, I guess I would need to be an "degree-granting institute" which I am not. I would also like to avoid rewriting all scripts I wrote during my PhD research to Python or Octave.
What is the actual MATLAB usage covered in licenses? Some time ago on the MATLAB website https://www.mathworks.com/pricing-licensing.html?prodcode=ML&intendeduse=home it was mentioned that one was not able to do research and publish results using MATLAB Home. I can’t see this note anymore. Now there is only "For personal use only. This license option is not for government, academic, commercial, or other organizational use". So, can I publish results (e.g. using the MATLAB plots)? Or can I publish MATLAB code only? Or can I only run such code? I can find plenty of blogs with hobbysts’ projects in the Internet using MATLAB, fully documented, so the "hobbyist" term remains not clear to me. For instance, if I write a C++ library under the Apache/MIT license which do some FFT computations under the hood, will I be able to use MATLAB Home just to verify solutions numerically?
Sincerely,
Mariusz M.
[1] https://www.mathworks.com/matlabcentral/answers/376174-how-to-get-permission-to-publish-my-matlab-programs
[2] https://www.mathworks.com/matlabcentral/answers/388329-what-a-license-i-need-to-publish-my-program-in-an-internet-site?s_tid=answers_rc1-3_p3_Topic
[3] https://www.mathworks.com/matlabcentral/answers/349000-does-a-home-license-allow-for-research-and-publishing-results-technical-papers-as-an-individual-o#answer_274396 Hi,
Since I faced some non-consistent answers in relevant MathWorks forums [1-3] I would like to clarify a few doubts I have regarding MATLAB licensing. I defended my PhD two years ago. As of now, I am no longer associated with any university or company using MATLAB. As a hobbyist, in my spare time I work individually on some non-commercial computer science research projects. I plan to publish the obtained simulation results and parts of MATLAB code in two research papers and a book (containing my PhD thesis with minor improvements).
Is the MATLAB Home license sufficient for my needs? The commercial license seems way too expensive and irrelevant in this case (not earning money), and for the academic license, I guess I would need to be an "degree-granting institute" which I am not. I would also like to avoid rewriting all scripts I wrote during my PhD research to Python or Octave.
What is the actual MATLAB usage covered in licenses? Some time ago on the MATLAB website https://www.mathworks.com/pricing-licensing.html?prodcode=ML&intendeduse=home it was mentioned that one was not able to do research and publish results using MATLAB Home. I can’t see this note anymore. Now there is only "For personal use only. This license option is not for government, academic, commercial, or other organizational use". So, can I publish results (e.g. using the MATLAB plots)? Or can I publish MATLAB code only? Or can I only run such code? I can find plenty of blogs with hobbysts’ projects in the Internet using MATLAB, fully documented, so the "hobbyist" term remains not clear to me. For instance, if I write a C++ library under the Apache/MIT license which do some FFT computations under the hood, will I be able to use MATLAB Home just to verify solutions numerically?
Sincerely,
Mariusz M.
[1] https://www.mathworks.com/matlabcentral/answers/376174-how-to-get-permission-to-publish-my-matlab-programs
[2] https://www.mathworks.com/matlabcentral/answers/388329-what-a-license-i-need-to-publish-my-program-in-an-internet-site?s_tid=answers_rc1-3_p3_Topic
[3] https://www.mathworks.com/matlabcentral/answers/349000-does-a-home-license-allow-for-research-and-publishing-results-technical-papers-as-an-individual-o#answer_274396 license, research, home MATLAB Answers — New Questions
TIFF save file not working
Hello, I have a 32bit grayscale tiff image composed by 41 slices.
I’m saving file always as a stack but it dont works:
Error using Tiff/writeAllStrips
Unable to retrieve ImageLength.
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
This is the portion of code
% salva il nuovo file con lo stesso nome ma aggiungendo "modified"
newFilename = fullfile(folder, [fileList(i).name(1:end-4) ‘_modified.tif’]);
t = Tiff(newFilename, ‘w’);
% ottieni le informazioni dalla prima immagine dello stack originale
info = imfinfo(filename);
disp(info(1))
% tagstruct.ImageLength = size(newStack(:,:,1),1);
% tagstruct.ImageWidth = size(newStack(:,:,1),2);
% tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.BitsPerSample = 32;
% tagstruct.SamplesPerPixel = 1;
% tagstruct.RowsPerStrip = 16;
% tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% tagstruct.Software = ‘MATLAB’;
% imposta le informazioni nella nuova immagine Tiff
t.setTag(‘Photometric’, 1);
t.setTag(‘Compression’, 1); % 1 = nessuna compressione, 8 = compressione Deflate
t.setTag(‘BitsPerSample’, info(1).BitsPerSample);
t.setTag(‘SamplesPerPixel’, info(1).SamplesPerPixel);
t.setTag(‘SampleFormat’, Tiff.SampleFormat.UInt);
t.setTag(‘ImageLength’, info(1).Height);
t.setTag(‘ImageWidth’, info(1).Width);
t.setTag(‘PlanarConfiguration’, Tiff.PlanarConfiguration.Chunky);
for j = 1:numImages
%t.setTag(info(j)); % commenta questa riga per testare se il problema è qui
t.write(newStack(:,:,j));
t.writeDirectory();
end
t.close();
This is iminfo of source file
FileModDate: ’30-dic-2022 09:47:14′
FileSize: 492005745
Format: ‘tif’
FormatVersion: []
Width: 2000
Height: 1500
BitDepth: 32
ColorType: ‘grayscale’
FormatSignature: [77 77 0 42]
ByteOrder: ‘big-endian’
NewSubFileType: 0
BitsPerSample: 32
Compression: ‘Uncompressed’
PhotometricInterpretation: ‘BlackIsZero’
StripOffsets: 225
SamplesPerPixel: 1
RowsPerStrip: 1500
StripByteCounts: 12000000
XResolution: []
YResolution: []
ResolutionUnit: ‘Inch’
Colormap: []
PlanarConfiguration: ‘Chunky’
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: ‘ImageJ=1.53n↵images=41↵slices=41↵loop=false↵min=0.0↵max=1.401298464324817E-45↵’
SampleFormat: ‘IEEE floating point’
Many thanksHello, I have a 32bit grayscale tiff image composed by 41 slices.
I’m saving file always as a stack but it dont works:
Error using Tiff/writeAllStrips
Unable to retrieve ImageLength.
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
This is the portion of code
% salva il nuovo file con lo stesso nome ma aggiungendo "modified"
newFilename = fullfile(folder, [fileList(i).name(1:end-4) ‘_modified.tif’]);
t = Tiff(newFilename, ‘w’);
% ottieni le informazioni dalla prima immagine dello stack originale
info = imfinfo(filename);
disp(info(1))
% tagstruct.ImageLength = size(newStack(:,:,1),1);
% tagstruct.ImageWidth = size(newStack(:,:,1),2);
% tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.BitsPerSample = 32;
% tagstruct.SamplesPerPixel = 1;
% tagstruct.RowsPerStrip = 16;
% tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% tagstruct.Software = ‘MATLAB’;
% imposta le informazioni nella nuova immagine Tiff
t.setTag(‘Photometric’, 1);
t.setTag(‘Compression’, 1); % 1 = nessuna compressione, 8 = compressione Deflate
t.setTag(‘BitsPerSample’, info(1).BitsPerSample);
t.setTag(‘SamplesPerPixel’, info(1).SamplesPerPixel);
t.setTag(‘SampleFormat’, Tiff.SampleFormat.UInt);
t.setTag(‘ImageLength’, info(1).Height);
t.setTag(‘ImageWidth’, info(1).Width);
t.setTag(‘PlanarConfiguration’, Tiff.PlanarConfiguration.Chunky);
for j = 1:numImages
%t.setTag(info(j)); % commenta questa riga per testare se il problema è qui
t.write(newStack(:,:,j));
t.writeDirectory();
end
t.close();
This is iminfo of source file
FileModDate: ’30-dic-2022 09:47:14′
FileSize: 492005745
Format: ‘tif’
FormatVersion: []
Width: 2000
Height: 1500
BitDepth: 32
ColorType: ‘grayscale’
FormatSignature: [77 77 0 42]
ByteOrder: ‘big-endian’
NewSubFileType: 0
BitsPerSample: 32
Compression: ‘Uncompressed’
PhotometricInterpretation: ‘BlackIsZero’
StripOffsets: 225
SamplesPerPixel: 1
RowsPerStrip: 1500
StripByteCounts: 12000000
XResolution: []
YResolution: []
ResolutionUnit: ‘Inch’
Colormap: []
PlanarConfiguration: ‘Chunky’
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: ‘ImageJ=1.53n↵images=41↵slices=41↵loop=false↵min=0.0↵max=1.401298464324817E-45↵’
SampleFormat: ‘IEEE floating point’
Many thanks Hello, I have a 32bit grayscale tiff image composed by 41 slices.
I’m saving file always as a stack but it dont works:
Error using Tiff/writeAllStrips
Unable to retrieve ImageLength.
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
This is the portion of code
% salva il nuovo file con lo stesso nome ma aggiungendo "modified"
newFilename = fullfile(folder, [fileList(i).name(1:end-4) ‘_modified.tif’]);
t = Tiff(newFilename, ‘w’);
% ottieni le informazioni dalla prima immagine dello stack originale
info = imfinfo(filename);
disp(info(1))
% tagstruct.ImageLength = size(newStack(:,:,1),1);
% tagstruct.ImageWidth = size(newStack(:,:,1),2);
% tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.BitsPerSample = 32;
% tagstruct.SamplesPerPixel = 1;
% tagstruct.RowsPerStrip = 16;
% tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% tagstruct.Software = ‘MATLAB’;
% imposta le informazioni nella nuova immagine Tiff
t.setTag(‘Photometric’, 1);
t.setTag(‘Compression’, 1); % 1 = nessuna compressione, 8 = compressione Deflate
t.setTag(‘BitsPerSample’, info(1).BitsPerSample);
t.setTag(‘SamplesPerPixel’, info(1).SamplesPerPixel);
t.setTag(‘SampleFormat’, Tiff.SampleFormat.UInt);
t.setTag(‘ImageLength’, info(1).Height);
t.setTag(‘ImageWidth’, info(1).Width);
t.setTag(‘PlanarConfiguration’, Tiff.PlanarConfiguration.Chunky);
for j = 1:numImages
%t.setTag(info(j)); % commenta questa riga per testare se il problema è qui
t.write(newStack(:,:,j));
t.writeDirectory();
end
t.close();
This is iminfo of source file
FileModDate: ’30-dic-2022 09:47:14′
FileSize: 492005745
Format: ‘tif’
FormatVersion: []
Width: 2000
Height: 1500
BitDepth: 32
ColorType: ‘grayscale’
FormatSignature: [77 77 0 42]
ByteOrder: ‘big-endian’
NewSubFileType: 0
BitsPerSample: 32
Compression: ‘Uncompressed’
PhotometricInterpretation: ‘BlackIsZero’
StripOffsets: 225
SamplesPerPixel: 1
RowsPerStrip: 1500
StripByteCounts: 12000000
XResolution: []
YResolution: []
ResolutionUnit: ‘Inch’
Colormap: []
PlanarConfiguration: ‘Chunky’
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: ‘ImageJ=1.53n↵images=41↵slices=41↵loop=false↵min=0.0↵max=1.401298464324817E-45↵’
SampleFormat: ‘IEEE floating point’
Many thanks tiff, save MATLAB Answers — New Questions
How to plot a polyhedron
Hi all,
I have a cloud of points that I have obtained by computing T = A*W where W = [w1 w2 w3 w4]’, A is a 3×4 matrix and T is a 3×1 matrix. All the parameters wi can be equal to [-1 0 1]. Hence, I found all the combination of W compunting by varying each wi and finally I have obtained all the 81 points T(:,i).
My goal is to depict the polyhedron, or 3D polygon, which is described by all the external points of the cloud T(:,i). I started to use the command "fill3(x,y,z,c)" and the results is quite good, but I’m doing it "by hands" and the cloud of points is not easily to visualize and hence is too difficoult to find all the vertices to plot each face of the polyhedron. It will be good if I can plot only the external points of the cloud or if there is a matlab command which plot the external surfaces of a cloud of points. I attach the picture of the cloud of points and some parts of the polygon I already found manually. Blue, red and green lines are related to x, y and z axis I order to help the visualization.
Someone can help me?
Thank you!
Matteo
<</matlabcentral/answers/uploaded_files/104893/cloud.png>>
<</matlabcentral/answers/uploaded_files/104894/poly.png>>Hi all,
I have a cloud of points that I have obtained by computing T = A*W where W = [w1 w2 w3 w4]’, A is a 3×4 matrix and T is a 3×1 matrix. All the parameters wi can be equal to [-1 0 1]. Hence, I found all the combination of W compunting by varying each wi and finally I have obtained all the 81 points T(:,i).
My goal is to depict the polyhedron, or 3D polygon, which is described by all the external points of the cloud T(:,i). I started to use the command "fill3(x,y,z,c)" and the results is quite good, but I’m doing it "by hands" and the cloud of points is not easily to visualize and hence is too difficoult to find all the vertices to plot each face of the polyhedron. It will be good if I can plot only the external points of the cloud or if there is a matlab command which plot the external surfaces of a cloud of points. I attach the picture of the cloud of points and some parts of the polygon I already found manually. Blue, red and green lines are related to x, y and z axis I order to help the visualization.
Someone can help me?
Thank you!
Matteo
<</matlabcentral/answers/uploaded_files/104893/cloud.png>>
<</matlabcentral/answers/uploaded_files/104894/poly.png>> Hi all,
I have a cloud of points that I have obtained by computing T = A*W where W = [w1 w2 w3 w4]’, A is a 3×4 matrix and T is a 3×1 matrix. All the parameters wi can be equal to [-1 0 1]. Hence, I found all the combination of W compunting by varying each wi and finally I have obtained all the 81 points T(:,i).
My goal is to depict the polyhedron, or 3D polygon, which is described by all the external points of the cloud T(:,i). I started to use the command "fill3(x,y,z,c)" and the results is quite good, but I’m doing it "by hands" and the cloud of points is not easily to visualize and hence is too difficoult to find all the vertices to plot each face of the polyhedron. It will be good if I can plot only the external points of the cloud or if there is a matlab command which plot the external surfaces of a cloud of points. I attach the picture of the cloud of points and some parts of the polygon I already found manually. Blue, red and green lines are related to x, y and z axis I order to help the visualization.
Someone can help me?
Thank you!
Matteo
<</matlabcentral/answers/uploaded_files/104893/cloud.png>>
<</matlabcentral/answers/uploaded_files/104894/poly.png>> 3d polygon, polyhedron, 3d plots MATLAB Answers — New Questions
MATLAB online not loading
When I log in and start the MATLAB Onramp course, and get to the first Module after the introduction, it just loads indefinitely. I have tried clearing session files, using a different browser, check internet speed and even using a mobile hotspot but it’s not helping.When I log in and start the MATLAB Onramp course, and get to the first Module after the introduction, it just loads indefinitely. I have tried clearing session files, using a different browser, check internet speed and even using a mobile hotspot but it’s not helping. When I log in and start the MATLAB Onramp course, and get to the first Module after the introduction, it just loads indefinitely. I have tried clearing session files, using a different browser, check internet speed and even using a mobile hotspot but it’s not helping. onramp MATLAB Answers — New Questions
Failed to Initialize MATLAB R2023b Runtime Library in Visual Studio 2019 C++ Project
I generated a C shared library type DLL for a custom function using the MATLAB Library Compiler and created a console C++ project in Visual Studio 2019 to call the DLL function and continue development. However, when initializing the DLL function, it reports a failure. I have set the PATH in the system environment variable to D:Program FilesMATLABMATLAB RuntimeR2023bbinwin64, and I have also set the include and library directories in Visual Studio 2019, and entered as many MATLAB runtime libraries as possible in the linker: mclmcr.lib; mclmcrrt.lib; libmat.lib; libmex.lib; libmx.lib; along with the custom .lib file. Why is the runtime library initialization still failing? My MATLAB version is R2023b, the compiler version is 23.2, and the runtime library version is 23. What could be causing the runtime library initialization to fail?I generated a C shared library type DLL for a custom function using the MATLAB Library Compiler and created a console C++ project in Visual Studio 2019 to call the DLL function and continue development. However, when initializing the DLL function, it reports a failure. I have set the PATH in the system environment variable to D:Program FilesMATLABMATLAB RuntimeR2023bbinwin64, and I have also set the include and library directories in Visual Studio 2019, and entered as many MATLAB runtime libraries as possible in the linker: mclmcr.lib; mclmcrrt.lib; libmat.lib; libmex.lib; libmx.lib; along with the custom .lib file. Why is the runtime library initialization still failing? My MATLAB version is R2023b, the compiler version is 23.2, and the runtime library version is 23. What could be causing the runtime library initialization to fail? I generated a C shared library type DLL for a custom function using the MATLAB Library Compiler and created a console C++ project in Visual Studio 2019 to call the DLL function and continue development. However, when initializing the DLL function, it reports a failure. I have set the PATH in the system environment variable to D:Program FilesMATLABMATLAB RuntimeR2023bbinwin64, and I have also set the include and library directories in Visual Studio 2019, and entered as many MATLAB runtime libraries as possible in the linker: mclmcr.lib; mclmcrrt.lib; libmat.lib; libmex.lib; libmx.lib; along with the custom .lib file. Why is the runtime library initialization still failing? My MATLAB version is R2023b, the compiler version is 23.2, and the runtime library version is 23. What could be causing the runtime library initialization to fail? library compiler, dll, visual studio2019, matlab compiler runtime, initialization, initialize() MATLAB Answers — New Questions